Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
DAOCache.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\cache\dao;
4
8
22 private $items;
27 protected $cache;
28
29 protected function getKey($class, $key) {
30 return \md5 ( $class . $key );
31 }
32
33 public function __construct($cacheSystem = MemCachedDriver::class) {
34 if (\is_string ( $cacheSystem )) {
35 $this->cache = new $cacheSystem ( CacheManager::getCacheSubDirectory ( 'objects' ), '.object' );
36 } else {
37 $this->cache = $cacheSystem;
38 }
39 }
40
41 public function store($class, $key, $object) {
42 $this->cache->store ( $this->getKey ( $class, $key ), $object );
43 }
44
45 public function fetch($class, $key) {
46 $k = $this->getKey ( $class, $key );
47 if (! isset ( $this->items [$k] )) {
48 $this->items [$k] = $this->cache->fetch ( $k );
49 }
50 return $this->items [$k];
51 }
52
53 public function delete($class, $key) {
54 $key = $this->getKey ( $class, $key );
55 if ($this->cache->exists ( $key )) {
56 return $this->cache->remove ( $key );
57 }
58 return false;
59 }
60}
61
Manager for caches (Router, Rest, models).
static getCacheSubDirectory(string $subDirectory)
Returns an absolute cache subdirectory.
Ubiquity\cache\dao$AbstractDAOCache This class is part of Ubiquity.
Ubiquity\cache\dao$DAOCache This class is part of Ubiquity.
Definition DAOCache.php:17
__construct($cacheSystem=MemCachedDriver::class)
Definition DAOCache.php:33
store($class, $key, $object)
Definition DAOCache.php:41
This class is responsible for storing Arrays in PHP files.
This class is responsible for storing values with MemCached.