Advertisement
Guest User

Untitled

a guest
Jul 21st, 2013
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Caches ACL checks to reduce load on database
  4.  *
  5.  * core.php:
  6.  * Configure::write ('Acl.classname', 'CacheDbAcl');
  7.  * Configure::write ('CacheDbAcl.cache', 'apc_acl');
  8.  *
  9.  * Cache::config ('apc_acl', array (...));
  10.  *
  11.  */
  12.  
  13. App::uses('AclInterface', 'Controller/Component/Acl');
  14. App::uses('DbAcl', 'Controller/Component/Acl');
  15.  
  16. class CacheDbAcl extends DbAcl
  17. {
  18.     private $cacheEngine;
  19.     public function __construct ()
  20.     {
  21.         parent::__construct();
  22.        
  23.         $this->cacheEngine = Configure::read ('CacheDbAcl.cache');
  24.        
  25.         if ( ! $this->cacheEngine )
  26.             $this->cacheEngine = 'default';
  27.     }
  28.    
  29.     public function check($aro, $aco, $action = "*")
  30.     {
  31.         $cacheKey = 'acl.' . md5(igbinary_serialize ($aro) . igbinary_serialize($aco) . $action);
  32.        
  33.         if ( ! Configure::read('Cache.disable') )
  34.         {
  35.             if ( ($cache = Cache::read ($cacheKey, $this->cacheEngine)) !== FALSE)
  36.                 return $cache;
  37.         }
  38.        
  39.         $result = parent::check ($aro, $aco, $action);
  40.         Cache::write ($cacheKey, $result, $this->cacheEngine);
  41.        
  42.         return $result;
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement