PluginProbe ʕ •ᴥ•ʔ
JetBackup – Backup, Restore & Migrate / trunk
JetBackup – Backup, Restore & Migrate vtrunk
3.1.22.3 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.4.8.1 1.4.9 1.5.0 1.5.1 1.5.1.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 1.6.10 1.6.11 1.6.12 1.6.13 1.6.15 1.6.5.1 1.6.8.8 1.6.9 1.6.9.1 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7.5 2.0.8.7 2.0.9.11 2.0.9.14 2.0.9.15 2.0.9.6 2.0.9.7 2.0.9.9 3.1.10.7 3.1.11.1 3.1.12.3 3.1.13.4 3.1.14.17 3.1.15.4 3.1.16.1 3.1.17.5 3.1.18.10 3.1.18.8 3.1.18.9 3.1.19.8 3.1.20.3 3.1.21.3 3.1.7.9 3.1.9.2 trunk 1.1.90 1.1.91 1.2.0 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2
backup / src / JetBackup / 3rdparty / SleekDB / Classes / CacheHandler.php
backup / src / JetBackup / 3rdparty / SleekDB / Classes Last commit date
.htaccess 1 year ago CacheHandler.php 1 year ago ConditionsHandler.php 1 year ago DocumentFinder.php 1 year ago DocumentReducer.php 1 year ago DocumentUpdater.php 4 months ago IoHelper.php 4 months ago NestedHelper.php 1 year ago index.html 1 year ago web.config 1 year ago
CacheHandler.php
129 lines
1 <?php
2
3
4 namespace SleekDB\Classes;
5
6
7 use SleekDB\Cache;
8 use SleekDB\Exceptions\IOException;
9 use SleekDB\QueryBuilder;
10
11 /**
12 * Class CacheHandler
13 * Bridge between Query and Cache
14 */
15 class CacheHandler
16 {
17 /**
18 * @var Cache
19 */
20 protected $cache;
21
22 protected $cacheTokenArray;
23 protected $regenerateCache;
24 protected $useCache;
25
26 /**
27 * CacheHandler constructor.
28 * @param string $storePath
29 * @param QueryBuilder $queryBuilder
30 */
31 public function __construct(string $storePath, QueryBuilder $queryBuilder)
32 {
33 $this->cacheTokenArray = $queryBuilder->_getCacheTokenArray();
34
35 $queryBuilderProperties = $queryBuilder->_getConditionProperties();
36 $this->useCache = $queryBuilderProperties["useCache"];
37 $this->regenerateCache = $queryBuilderProperties["regenerateCache"];
38
39 $this->cache = new Cache($storePath, $this->_getCacheTokenArray(), $queryBuilderProperties["cacheLifetime"]);
40 }
41
42 /**
43 * @return Cache
44 */
45 public function getCache(): Cache
46 {
47 return $this->cache;
48 }
49
50 /**
51 * Get results from cache
52 * @return array|null
53 * @throws IOException
54 */
55 public function getCacheContent($getOneDocument)
56 {
57 if($this->getUseCache() !== true){
58 return null;
59 }
60
61 $this->updateCacheTokenArray(['oneDocument' => $getOneDocument]);
62
63 if($this->regenerateCache === true) {
64 $this->getCache()->delete();
65 }
66
67 $cacheResults = $this->getCache()->get();
68 if(is_array($cacheResults)) {
69 return $cacheResults;
70 }
71
72 return null;
73 }
74
75 /**
76 * Add content to cache
77 * @param array $results
78 * @throws IOException
79 */
80 public function setCacheContent(array $results)
81 {
82 if($this->getUseCache() === true){
83 $this->getCache()->set($results);
84 }
85 }
86
87 /**
88 * Delete all cache files that have no lifetime.
89 * @return bool
90 */
91 public function deleteAllWithNoLifetime(): bool
92 {
93 return $this->getCache()->deleteAllWithNoLifetime();
94 }
95
96 /**
97 * Returns a reference to the array used for cache token generation
98 * @return array
99 */
100 public function &_getCacheTokenArray(): array
101 {
102 return $this->cacheTokenArray;
103 }
104
105 /**
106 * @param array $tokenUpdate
107 */
108 private function updateCacheTokenArray(array $tokenUpdate)
109 {
110 if(empty($tokenUpdate)) {
111 return;
112 }
113 $cacheTokenArray = $this->_getCacheTokenArray();
114 foreach ($tokenUpdate as $key => $value){
115 $cacheTokenArray[$key] = $value;
116 }
117 $this->cacheTokenArray = $cacheTokenArray;
118 }
119
120 /**
121 * Status if cache is used or not
122 * @return bool
123 */
124 private function getUseCache(): bool
125 {
126 return $this->useCache;
127 }
128
129 }