We have a REST Webservice build with Symfony3 and PHP7. The application is served via Nginx and PHP-FPM.
The Webservice returns a list of products. Products inside the list are filtered by attributes. The result would be the list with a subset of its products, filtered by attributes. Those attributes are send via GET parameters in the url. For now there are 4 parameters resulting in around 1 million combination of Urls per product. Product data changes constantly.
Example List before filtering:
{
name: "list1",
products: [
{
name: "product1"
},
{
name: "product2"
]
}
Example List after filtering:
{
name: "list1",
products: [
{
name: "product2"
]
}
Example API resource: /list?slug=list1&filter1=foo&filter2=bar&filter3=baz
In order to improve performance we want to cache requests with Nginx fastcgi_cache. The response would be cached with a cache key that equals the request url.
When we cache the responses for 1 hour we need to invalidate cache entries when data of a product changes. So we need to invalidate all cache entries that include that product.
So what I could do is, I could find out all Lists that include the product. And than create every combination of filters and create all possible urls for the list. Then invalidate those entries.
I think that would need very much resources to invalidate/refresh the cache.
How to properly cache and properly invalidate the cache in such situations?
Similar unanswered question Should processing/filtering be performed client side or server side for catalog based apps