File tree Expand file tree Collapse file tree
src/imperazim/components/cache Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -62,6 +62,27 @@ public static function get(string $key): mixed {
6262 return $ cacheItem ['value ' ];
6363 }
6464
65+ /**
66+ * Checks if a cache key exists and is not expired.
67+ * @param string $key The cache key.
68+ * @return bool True if the key exists and is not expired, false otherwise.
69+ */
70+ public static function has (string $ key ): bool {
71+ if (!isset (self ::$ cache [$ key ])) {
72+ return false ;
73+ }
74+
75+ $ cacheItem = self ::$ cache [$ key ];
76+
77+ // Check if the item has expired
78+ if ($ cacheItem ['expires_at ' ] !== null && $ cacheItem ['expires_at ' ] < time ()) {
79+ self ::invalidate ($ key );
80+ return false ;
81+ }
82+
83+ return true ;
84+ }
85+
6586 /**
6687 * Invalidates a cached item, removing it from the cache.
6788 * @param string $key The cache key.
You can’t perform that action at this time.
0 commit comments