Resolve AT Protocol DIDs, handles, and schemas with intelligent caching for Laravel
at dev 1.4 kB view raw
1<?php 2 3namespace SocialDept\AtpResolver\Cache; 4 5use Illuminate\Contracts\Cache\Repository; 6use SocialDept\AtpResolver\Contracts\CacheStore; 7 8class LaravelCacheStore implements CacheStore 9{ 10 protected string $prefix = 'beacon:'; 11 12 /** 13 * Create a new Laravel cache store instance. 14 */ 15 public function __construct( 16 protected Repository $cache 17 ) { 18 } 19 20 /** 21 * Get a cached value. 22 * 23 * @param string $key 24 */ 25 public function get(string $key): mixed 26 { 27 return $this->cache->get($this->prefix.$key); 28 } 29 30 /** 31 * Store a value in the cache. 32 * 33 * @param string $key 34 * @param mixed $value 35 * @param int $ttl Time to live in seconds 36 */ 37 public function put(string $key, mixed $value, int $ttl): void 38 { 39 $this->cache->put($this->prefix.$key, $value, $ttl); 40 } 41 42 /** 43 * Check if a key exists in the cache. 44 * 45 * @param string $key 46 */ 47 public function has(string $key): bool 48 { 49 return $this->cache->has($this->prefix.$key); 50 } 51 52 /** 53 * Remove a value from the cache. 54 * 55 * @param string $key 56 */ 57 public function forget(string $key): void 58 { 59 $this->cache->forget($this->prefix.$key); 60 } 61 62 /** 63 * Clear all cached values. 64 */ 65 public function flush(): void 66 { 67 $this->cache->flush(); 68 } 69}