Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
DAOSerialCache.php
Go to the documentation of this file.
1<?php
2
3namespace Ubiquity\cache\dao;
4
9use Ubiquity\cache\system\ArrayCache;
10
20
25 protected $serializer;
26
31 protected $cache;
32
33 protected function getKey($class, $key) {
34 return \md5 ( $class . $key );
35 }
36
37 public function __construct($cacheSystem = ArrayCache::class, $serializer = PhpSerializer::class) {
38 if (\is_string ( $cacheSystem )) {
39 $this->cache = new $cacheSystem ( CacheManager::getCacheSubDirectory ( 'objects' ), '.object' );
40 } else {
41 $this->cache = $cacheSystem;
42 }
43 $this->serializer = new $serializer ();
44 }
45
46 public function store($class, $key, $object) {
47 $this->cache->store ( $this->getKey ( $class, $key ), $this->serializer->serialize ( $object ) );
48 }
49
50 public function fetch($class, $key) {
51 $result = $this->cache->fetch ( $this->getKey ( $class, $key ) );
52 if ($result) {
53 return $this->serializer->unserialize ( $result );
54 }
55 return false;
56 }
57
58 public function delete($class, $key) {
59 $key = $this->getKey ( $class, $key );
60 if ($this->cache->exists ( $key )) {
61 return $this->cache->remove ( $key );
62 }
63 return false;
64 }
65}
66
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$DAOSerialCache This class is part of Ubiquity.
__construct($cacheSystem=ArrayCache::class, $serializer=PhpSerializer::class)
This class is responsible for storing Arrays in PHP files.
Ubiquity\contents\serializers$PhpSerializer This class is part of Ubiquity.
Ubiquity\contents\serializers$SerializerInterface This class is part of Ubiquity.