@@ -60,7 +60,7 @@ $classBoundCache = new ClassBoundCache($fileBoundCache);
6060
6161// Put the $myDataToCache object in cache.
6262// If the FooBar class is modified, the cache item is purged.
63- $classBoundCache->set('cache_key', $myDataToCache, FooBar::class);
63+ $classBoundCache->set('cache_key', $myDataToCache, new ReflectionClass( FooBar::class) );
6464
6565// Fetching data
6666$myDataToCache = $classBoundCache->get('cache_key');
@@ -88,3 +88,28 @@ use TheCodingMachine\CacheUtils\ClassBoundMemoryAdapter;
8888
8989$classBoundCache = new ClassBoundMemoryAdapter(new ClassBoundCache($psr16Cache));
9090```
91+
92+ ### Easier interface with cache contracts
93+
94+ You can even get an easier to use class bound cache using the ` ClassBoundCacheContract ` .
95+
96+ ``` php
97+ use TheCodingMachine\CacheUtils\FileBoundCache;
98+ use TheCodingMachine\CacheUtils\ClassBoundCache;
99+ use TheCodingMachine\CacheUtils\ClassBoundMemoryAdapter;
100+ use TheCodingMachine\CacheUtils\ClassBoundCacheContract;
101+
102+ $fileBoundCache = new FileBoundCache($psr16Cache);
103+ $classBoundCache = new ClassBoundMemoryAdapter(new ClassBoundCache($psr16Cache));
104+ $classBoundCacheContract = new ClassBoundCacheContract(new ClassBoundCache($fileBoundCache));
105+
106+ // Put the $myDataToCache object in cache.
107+ // If the FooBar class is modified, the cache item is purged.
108+ $classBoundCache->get(new ReflectionClass(FooBar::class), function() {
109+ // let's return the item to be cached.
110+ // this function is called only if the item is not in cache yet.
111+ });
112+ ```
113+
114+ With cache contracts, there is not setters. Only a getter that takes in parameter a callable that will resolve the
115+ cache item if the item is not available in the cache.
0 commit comments