aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/cache/MemoryCache.class.php
diff options
context:
space:
mode:
authorMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2024-06-18 13:18:06 +0000
committerMarcus Eibrink-Lunzenauer <lunzenauer@elan-ev.de>2024-06-18 13:18:06 +0000
commit33fd1358507b4a5abb3dcebe78d407d0567717c1 (patch)
tree6bd8f6959da4c3fc1b8907c0bbc28eb9e10d4a5a /lib/classes/cache/MemoryCache.class.php
parent42d46671c0309bddb71a91bbfdc5f2fa2e44384e (diff)
Deprecate `StudipAutoloader` and use composer's `autoload`
Closes #4282 Merge request studip/studip!3099
Diffstat (limited to 'lib/classes/cache/MemoryCache.class.php')
-rw-r--r--lib/classes/cache/MemoryCache.class.php98
1 files changed, 0 insertions, 98 deletions
diff --git a/lib/classes/cache/MemoryCache.class.php b/lib/classes/cache/MemoryCache.class.php
deleted file mode 100644
index 7c00753..0000000
--- a/lib/classes/cache/MemoryCache.class.php
+++ /dev/null
@@ -1,98 +0,0 @@
-<?php
-
-namespace Studip\Cache;
-
-use DateTime;
-use Psr\Cache\CacheItemInterface;
-
-/**
- * The php memory implementation of the StudipCache interface.
- *
- * @author Jan-Hendrik Willms <tleilax+studip@gmail.com>
- * @license GPL2 or any later version
- * @since Stud.IP 5.0
- */
-class MemoryCache extends Cache
-{
- protected array $memory_cache = [];
-
- /**
- * Expires just a single key.
- *
- * @param string $arg the key
- */
- public function expire($arg)
- {
- unset($this->memory_cache[$arg]);
- }
-
- /**
- * Expire all items from the cache.
- */
- public function flush()
- {
- $this->memory_cache = [];
- }
-
- public static function getDisplayName(): string
- {
- return 'Memory cache';
- }
-
- public function getStats(): array
- {
- return [];
- }
-
- public static function getConfig(): array
- {
- return [];
- }
-
- /**
- * @inheritDoc
- */
- public function getItem(string $key): CacheItemInterface
- {
- $item = new Item($key);
- if (!isset($this->memory_cache[$key])) {
- return $item;
- }
- if ($this->memory_cache[$key]['expires'] < time()) {
- $this->expire($key);
- return $item;
- }
- $item->setHit();
- $item->set($this->memory_cache[$key]['data']);
- if (!empty($this->memory_cache[$key]['expires'])) {
- $expiration = new DateTime();
- $expiration->setTimestamp($this->memory_cache[$key]['expires']);
- $item->expiresAt($expiration);
- }
- return $item;
- }
-
- /**
- * @inheritDoc
- */
- public function hasItem(string $key): bool
- {
- return isset($this->memory_cache[$key])
- && $this->memory_cache[$key]['expires'] < time();
- }
-
- /**
- * @inheritDoc
- */
- public function save(CacheItemInterface $item): bool
- {
- $expiration = $this->getExpiration($item);
-
- $this->memory_cache[$item->getKey()] = [
- 'expires' => $expiration + time(),
- 'data' => $item->get(),
- ];
-
- return true;
- }
-}