8use Ubiquity\cache\system\ArrayCache;
31 protected function getKey($tableName, $condition) {
32 return $tableName . \md5 ( $condition );
35 public function __construct($cacheSystem = ArrayCache::class, $config = [ ]) {
36 if (\is_string ( $cacheSystem )) {
39 $this->cache = $cacheSystem;
45 if (isset ( $this->memoryCache [$key] )) {
46 return $this->memoryCache [$key];
48 if ($this->cache->exists ( $key )) {
49 return $this->memoryCache [$key] = $this->cache->fetch ( $key );
61 abstract public function store($tableName, $condition, $result);
70 public function fetch($tableName, $condition) {
71 $key = $this->
getKey ( $tableName, $condition );
72 if (isset ( $this->memoryCache [$key] )) {
73 return $this->memoryCache [$key];
75 if ($this->cache->exists ( $key )) {
76 return $this->memoryCache [$key] = $this->cache->fetch ( $key );
88 abstract public function delete($tableName, $condition);
90 public function clear($matches =
'') {
91 $this->cache->clear ( $matches );
94 public function remove($key) {
95 $this->cache->remove ( $key );
99 self::$active = $value;
103 foreach ( $this->toStore as $k ) {
104 $this->cache->store ( $k, $this->memoryCache [$k] );
106 $this->toStore = [ ];
Manager for caches (Router, Rest, models).
static getCacheSubDirectory(string $subDirectory)
Returns an absolute cache subdirectory.
Abstract class for database caching Ubiquity\cache\database$DbCache This class is part of Ubiquity.
getKey($tableName, $condition)
__construct($cacheSystem=ArrayCache::class, $config=[])
fetch($tableName, $condition)
Fetches data stored for the given condition in table.
store($tableName, $condition, $result)
Caches the given data with the given key (tableName+md5(condition)).