diff options
| author | Rami Jasim <rami.jasim1@uni-oldenburg.de> | 2025-01-27 13:01:54 +0100 |
|---|---|---|
| committer | Rami Jasim <rami.jasim1@uni-oldenburg.de> | 2025-01-27 13:01:54 +0100 |
| commit | 27e141b98eb4395736ef605275647b4dda2123ef (patch) | |
| tree | 0f8b16e57d081d7c1706e1ede8b5f93ec16a47d8 /lib/classes/cache | |
| parent | e5a8b35103c4079b8339e8a60b9a1d105c507e6f (diff) | |
add general caching structureissue-5183
Diffstat (limited to 'lib/classes/cache')
| -rw-r--r-- | lib/classes/cache/DbCache.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/classes/cache/DbCache.php b/lib/classes/cache/DbCache.php index 5714ce9..783ab10 100644 --- a/lib/classes/cache/DbCache.php +++ b/lib/classes/cache/DbCache.php @@ -112,6 +112,35 @@ class DbCache extends Cache return $item; } + public function getItems(array $keys = []): array + { + $query = "SELECT `cache_key`, `content`, `expires` + FROM `cache` + WHERE `cache_key` IN (:keys) + AND `expires` > UNIX_TIMESTAMP()"; + $results = DBManager::get()->fetchAll($query, [':keys' => $keys]); + $items = []; + foreach ($results as $result) { + $item = new Item($result['cache_key']); + $item->setHit(); + if ($result['content']) { + $item->set(unserialize($result['content'])); + } + if ($result['expires']) { + $expiration = new \DateTime(); + $expiration->setTimestamp($result['expires']); + $item->expiresAt($expiration); + } + $items[$result['cache_key']] = $item; + } + // Don't return null, fill remaining keys + foreach (array_diff($keys, array_keys($items)) as $remaining_key) { + $items[$remaining_key] = new Item($remaining_key); + } + return $items; + } + + /** * @inheritDoc */ |
