✏️ 正在编辑: Cache.php
路径:
/srv/systems_dir/koruspay/library/Core/DbTable/Cache.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php class Core_DbTable_Cache extends Core_DbTable { protected $cache; protected $cacheAtivo = true; public function setCacheAtivo($bool) { $this->cacheAtivo = (boolean) $bool; } public function __construct($config = array(), $definition = null) { $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap'); $cachemanager = $bootstrap->getResource('cachemanager'); $cache = $cachemanager->getCache('database'); $this->cache = $cache ? $cache : null; parent::__construct($config, $definition); } public function fetchAll($where = null, $order = null, $count = null, $offset = null) { if ($this->cacheAtivo && $this->cache) { $cacheId = get_class($this) . '_' . md5(__METHOD__ . Zend_Json::encode(array($where, $order, $count, $offset))); $result = $this->cache->load($cacheId); if (!$result) { $result = parent::fetchAll($where, $order, $count, $offset); $this->cache->save($result, $cacheId, array(get_class($this), 'fetchAll')); } } else { $result = parent::fetchAll($where, $order, $count, $offset); } return $result; } public function insert(array $data) { if ($this->cache) { $this->cache->clean( Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(get_class($this), 'fetchAll') ); } return parent::insert($data); } public function update(array $data, $where) { if ($this->cache) { $this->cache->clean( Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(get_class($this), 'fetchAll') ); } return parent::update($data, $where); } public function delete($where) { if ($this->cache) { $this->cache->clean( Zend_Cache::CLEANING_MODE_MATCHING_TAG, array(get_class($this), 'fetchAll') ); } return parent::delete($where); } }
💾 保存文件
← 返回文件管理器