I create a cache key with nginx based on a URI request and request parameters, which checks memcache directly and then serves the page from PHP-FPM if the cache key is not found. My problem is that many URLs have query string parameters that go in different orders and thus generate two or more separate cache keys for each response.
Cache Settings:
set $cache_key "$uri?$args";
Thus, the URLs that enter them with the query string parameters in different orders ultimately create several possible cache keys for the same type:
http://example.com/api/2.2/events.json?id=53&type=wedding&sort=title&limit=10 http://example.com/api/2.2/events.json?id=53&limit=10&type=wedding&sort=title http://example.com/api/2.2/events.json?id=53&limit=10&sort=title&type=wedding
Nauseum ad for n! capabilities...
The end result is that memcache often pops up much faster than needed, because I have potential n! -1 duplicate copies of cached content simply because query string parameters arrive in a different order. Is there a way that I can sort them alphabetically before setting the cache key to avoid this? Are there other ways to elegantly solve this problem?
caching nginx
Vance lucas
source share