1111
1212class CacheEntityCollectionStore implements EntityCollectionStoreInterface
1313{
14- protected const PREFIX = 'federation_entities ' ;
14+ protected const KEY_FEDERATED_ENTITIES = 'federation_entities ' ;
15+
16+ protected const KEY_LAST_UPDATED = 'last_updated ' ;
1517
1618
1719 public function __construct (
@@ -22,13 +24,16 @@ public function __construct(
2224 }
2325
2426
27+ /**
28+ * @inheritDoc
29+ */
2530 public function store (string $ trustAnchorId , array $ entities , int $ ttl ): void
2631 {
2732 try {
2833 $ this ->cacheDecorator ->set (
2934 $ this ->helpers ->json ()->encode ($ entities ),
3035 $ ttl ,
31- self ::PREFIX ,
36+ self ::KEY_FEDERATED_ENTITIES ,
3237 $ trustAnchorId ,
3338 );
3439 } catch (Throwable $ throwable ) {
@@ -41,11 +46,14 @@ public function store(string $trustAnchorId, array $entities, int $ttl): void
4146 }
4247
4348
49+ /**
50+ * @inheritDoc
51+ */
4452 public function get (string $ trustAnchorId ): ?array
4553 {
4654 try {
4755 /** @var ?string $cached */
48- $ cached = $ this ->cacheDecorator ->get (null , self ::PREFIX , $ trustAnchorId );
56+ $ cached = $ this ->cacheDecorator ->get (null , self ::KEY_FEDERATED_ENTITIES , $ trustAnchorId );
4957
5058 if (is_null ($ cached )) {
5159 return null ;
@@ -69,15 +77,79 @@ public function get(string $trustAnchorId): ?array
6977 }
7078
7179
80+ /**
81+ * @inheritDoc
82+ */
7283 public function clear (string $ trustAnchorId ): void
7384 {
7485 try {
75- $ this ->cacheDecorator ->delete (self ::PREFIX , $ trustAnchorId );
86+ $ this ->cacheDecorator ->delete (self ::KEY_FEDERATED_ENTITIES , $ trustAnchorId );
7687 } catch (Throwable $ throwable ) {
7788 $ this ->logger ?->error('Unable to clear entities from cache. ' , [
7889 'trustAnchorId ' => $ trustAnchorId ,
7990 'exception_message ' => $ throwable ->getMessage (),
8091 ]);
8192 }
8293 }
94+
95+
96+ /**
97+ * @inheritDoc
98+ */
99+ public function storeLastUpdated (string $ trustAnchorId , int $ timestamp , int $ ttl ): void
100+ {
101+ try {
102+ $ this ->cacheDecorator ->set (
103+ (string )$ timestamp ,
104+ $ ttl ,
105+ self ::KEY_LAST_UPDATED ,
106+ $ trustAnchorId ,
107+ );
108+ } catch (Throwable $ throwable ) {
109+ $ this ->logger ?->error('Unable to store last updated timestamp in cache. ' , [
110+ 'trustAnchorId ' => $ trustAnchorId ,
111+ 'timestamp ' => $ timestamp ,
112+ 'exception_message ' => $ throwable ->getMessage (),
113+ ]);
114+ }
115+ }
116+
117+
118+ /**
119+ * @inheritDoc
120+ */
121+ public function getLastUpdated (string $ trustAnchorId ): ?int
122+ {
123+ try {
124+ $ lastUpdated = $ this ->cacheDecorator ->get (null , self ::KEY_LAST_UPDATED , $ trustAnchorId );
125+ } catch (Throwable $ throwable ) {
126+ $ this ->logger ?->error('Unable to retrieve last updated timestamp from cache. ' , [
127+ 'trustAnchorId ' => $ trustAnchorId ,
128+ 'exception_message ' => $ throwable ->getMessage (),
129+ ]);
130+ return null ;
131+ }
132+
133+ if (is_int ($ lastUpdated )) {
134+ return $ lastUpdated ;
135+ }
136+
137+ return null ;
138+ }
139+
140+
141+ /**
142+ * @inheritDoc
143+ */
144+ public function clearLastUpdated (string $ trustAnchorId ): void
145+ {
146+ try {
147+ $ this ->cacheDecorator ->delete (self ::KEY_LAST_UPDATED , $ trustAnchorId );
148+ } catch (Throwable $ throwable ) {
149+ $ this ->logger ?->error('Unable to clear last updated timestamp from cache. ' , [
150+ 'trustAnchorId ' => $ trustAnchorId ,
151+ 'exception_message ' => $ throwable ->getMessage (),
152+ ]);
153+ }
154+ }
83155}
0 commit comments