Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Caches ACL checks to reduce load on database
- *
- * core.php:
- * Configure::write ('Acl.classname', 'CacheDbAcl');
- * Configure::write ('CacheDbAcl.cache', 'apc_acl');
- *
- * Cache::config ('apc_acl', array (...));
- *
- */
- App::uses('AclInterface', 'Controller/Component/Acl');
- App::uses('DbAcl', 'Controller/Component/Acl');
- class CacheDbAcl extends DbAcl
- {
- private $cacheEngine;
- public function __construct ()
- {
- parent::__construct();
- $this->cacheEngine = Configure::read ('CacheDbAcl.cache');
- if ( ! $this->cacheEngine )
- $this->cacheEngine = 'default';
- }
- public function check($aro, $aco, $action = "*")
- {
- $cacheKey = 'acl.' . md5(igbinary_serialize ($aro) . igbinary_serialize($aco) . $action);
- if ( ! Configure::read('Cache.disable') )
- {
- if ( ($cache = Cache::read ($cacheKey, $this->cacheEngine)) !== FALSE)
- return $cache;
- }
- $result = parent::check ($aro, $aco, $action);
- Cache::write ($cacheKey, $result, $this->cacheEngine);
- return $result;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement