Open vaclavgreif opened 3 years ago
@vaclavgreif did you figure that out? I need that too :/
Hi Marcus, in the end I did something like this:
$cache_rules = [
new Rule( Rule::REQUEST_TYPE_GET, 'agreements', 400 ),
];
$cache = new Cache(
new FilesystemAdapter( 'testCache', 0, __DIR__ ),
$cache_rules
);
$careCloud = new MySdk( $config, $cache );
and in the MySDK:
if ( $this->cache ) {
$strategy = new DelegatingCacheStrategy( $defaultStrategy = new NullCacheStrategy() );
foreach ( $this->cache->getRules() as $item ) {
$strategy->registerRequestMatcher(
new CacheRequestMatcher( $item ),
new GreedyCacheStrategy(
new Psr6CacheStorage( $this->cache->getCacheItemPool() ),
$item->getTtl() )
);
}
$stack->push( new CacheMiddleware( $strategy ) );
}
I'm defining a
DelegatingCacheStrategy
, and I'm using a simple config to define which endpoint should be cached:and the matcher method looks like this:
This works great, but I'd need to be able to define different TTLs for different endpoints. Is there a way to set that somehow?