@@ -189,6 +189,12 @@ cache for your application.
189189If the ` default_memoize_seconds ` is set to ` -1 ` this config is ignored and a default in-memory implementation
190190is used (service ` rikudou.memoize.internal_cache ` , class [ ` InMemoryCachePool ` ] ( src/Cache/InMemoryCachePool.php ) ).
191191
192+ ### key_specifier_service
193+
194+ This parameter allows you to specify a service that will alter the cache key. This is useful if your app relies on
195+ some kind of global state (like currently authenticated user etc.). It must implement the
196+ [ CacheKeySpecifier] ( src/Cache/KeySpecifier/CacheKeySpecifier.php ) interface.
197+
192198### Default configuration
193199
194200Generated by ` php bin/console config:dump rikudou_memoize `
@@ -205,6 +211,9 @@ rikudou_memoize:
205211
206212 # The default cache service to use. If default_memoize_seconds is set to -1 this setting is ignored and internal service is used.
207213 cache_service : cache.app
214+
215+ # The service to use to alter the cache key. Useful if you need to alter the cache key based on some global state.
216+ key_specifier_service : rikudou.memoize.key_specifier.null
208217` ` `
209218
210219## Example proxy class
@@ -258,18 +267,20 @@ class Calculator implements CalculatorInterface
258267
259268namespace App\Memoized;
260269
261- final class Calculator_Proxy_97bcf9ddeba8fffab6ecd550cf2ea6d6 implements \App\Service\CalculatorInterface
270+ final class Calculator_Proxy_422705a42881a5490e7996fe93245734 implements \App\Service\CalculatorInterface
262271{
263272 public function __construct(
264273 private readonly \App\Service\Calculator $original,
265274 private readonly \Psr\Cache\CacheItemPoolInterface $cache,
266275 private readonly \Rikudou\MemoizeBundle\Cache\InMemoryCachePool $internalCache,
276+ private readonly \Rikudou\MemoizeBundle\Cache\KeySpecifier\CacheKeySpecifier $cacheKeySpecifier,
267277 ) {}
268278
269279 public function add(int $a, int $b): int {
270280 $cacheKey = '';
271281 $cacheKey .= serialize($a);
272282 $cacheKey .= serialize($b);
283+ $cacheKey .= $this->cacheKeySpecifier->generate();
273284 $cacheKey = hash('sha512', $cacheKey);
274285 $cacheKey = "rikudou_memoize_AppServiceCalculator_add_{$cacheKey}";
275286
@@ -288,6 +299,7 @@ final class Calculator_Proxy_97bcf9ddeba8fffab6ecd550cf2ea6d6 implements \App\Se
288299 $cacheKey = '';
289300 $cacheKey .= serialize($a);
290301 $cacheKey .= serialize($b);
302+ $cacheKey .= $this->cacheKeySpecifier->generate();
291303 $cacheKey = hash('sha512', $cacheKey);
292304 $cacheKey = "rikudou_memoize_AppServiceCalculator_sub_{$cacheKey}";
293305
@@ -308,6 +320,7 @@ final class Calculator_Proxy_97bcf9ddeba8fffab6ecd550cf2ea6d6 implements \App\Se
308320
309321 public function someVoidMethod(): void {
310322 $cacheKey = '';
323+ $cacheKey .= $this->cacheKeySpecifier->generate();
311324 $cacheKey = hash('sha512', $cacheKey);
312325 $cacheKey = "rikudou_memoize_AppServiceCalculator_someVoidMethod_{$cacheKey}";
313326
@@ -326,4 +339,4 @@ final class Calculator_Proxy_97bcf9ddeba8fffab6ecd550cf2ea6d6 implements \App\Se
326339 }
327340
328341}
329- ```
342+ ```
0 commit comments