{"action":"created","issue":{"url":"https://api.github.com/repos/tedious/Stash/issues/201","labels_url":"https://api.github.com/repos/tedious/Stash/issues/201/labels{/name}","comments_url":"https://api.github.com/repos/tedious/Stash/issues/201/comments","events_url":"https://api.github.com/repos/tedious/Stash/issues/201/events","html_url":"https://github.com/tedious/Stash/issues/201","id":53766533,"number":201,"title":"Redis/Memcache purge behavior might lead to cache pollution","user":{"login":"mlafeldt","id":158074,"avatar_url":"https://avatars.githubusercontent.com/u/158074?v=3","gravatar_id":"","url":"https://api.github.com/users/mlafeldt","html_url":"https://github.com/mlafeldt","followers_url":"https://api.github.com/users/mlafeldt/followers","following_url":"https://api.github.com/users/mlafeldt/following{/other_user}","gists_url":"https://api.github.com/users/mlafeldt/gists{/gist_id}","starred_url":"https://api.github.com/users/mlafeldt/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlafeldt/subscriptions","organizations_url":"https://api.github.com/users/mlafeldt/orgs","repos_url":"https://api.github.com/users/mlafeldt/repos","events_url":"https://api.github.com/users/mlafeldt/events{/privacy}","received_events_url":"https://api.github.com/users/mlafeldt/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-01-08T16:03:06Z","updated_at":"2015-01-09T01:05:20Z","closed_at":null,"body":"When items are currently purged in Redis/Memcache, a path key will be created/incremented for each item. The key [has no TTL set](https://github.com/tedious/Stash/blob/dc04d658b75ecd38e3892af657bf6e28a7057909/src/Stash/Driver/Redis.php#L247), so the cache will get slowly polluted over time, at least when using the [volatile-lru strategy in Redis](http://redis.io/topics/lru-cache).\r\n\r\nWhat do think about making the TTL of path keys configurable? This would make sense for us, since we know the maximum TTL of all items (and sub-items).\r\n\r\nFor Redis, the TTL could be passed [here](https://github.com/tedious/Stash/blob/dc04d658b75ecd38e3892af657bf6e28a7057909/src/Stash/Item.php#L187) from where it is passed through and eventually ends up being used [here](https://github.com/tedious/Stash/blob/dc04d658b75ecd38e3892af657bf6e28a7057909/src/Stash/Driver/Redis.php#L237).\r\n\r\nAlso, this might be added to other drivers as well.\r\n\r\nWhat do you think?\r\n\r\n/cc @s0enke "},"comment":{"url":"https://api.github.com/repos/tedious/Stash/issues/comments/69278606","html_url":"https://github.com/tedious/Stash/issues/201#issuecomment-69278606","issue_url":"https://api.github.com/repos/tedious/Stash/issues/201","id":69278606,"user":{"login":"tedivm","id":121709,"avatar_url":"https://avatars.githubusercontent.com/u/121709?v=3","gravatar_id":"","url":"https://api.github.com/users/tedivm","html_url":"https://github.com/tedivm","followers_url":"https://api.github.com/users/tedivm/followers","following_url":"https://api.github.com/users/tedivm/following{/other_user}","gists_url":"https://api.github.com/users/tedivm/gists{/gist_id}","starred_url":"https://api.github.com/users/tedivm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tedivm/subscriptions","organizations_url":"https://api.github.com/users/tedivm/orgs","repos_url":"https://api.github.com/users/tedivm/repos","events_url":"https://api.github.com/users/tedivm/events{/privacy}","received_events_url":"https://api.github.com/users/tedivm/received_events","type":"User","site_admin":false},"created_at":"2015-01-09T01:05:20Z","updated_at":"2015-01-09T01:05:20Z","body":"Nice catch. I read through the redis documentation and want to quote a relevant point-\r\n\r\n> volatile-lru: evict keys trying to remove the less recently used (LRU) keys first, but only among keys that have an expire set, in order to make space for the new data added.\r\n\r\nWhat this says to me is that a key with no expiration will sit there forever. However, a key with an expiration- even if it's ridiculously far into the future- will fall into the LRU strategy. So if we set a default ttl of something like ten years for the keys and data around it everything will act as if it's a standard LRU system.\r\n\r\nWhat I think needs to be done is a modification of the [store function](https://github.com/tedious/Stash/blob/dc04d658b75ecd38e3892af657bf6e28a7057909/src/Stash/Driver/Redis.php#L219) to make is so that if no expiration is passed the default one (which is so ridiculously far into the future that it's the equivalent of not putting a ttl in at all) gets used.\r\n\r\nI don't believe this issue exists on memcache though, as it's LRU strategy ignores existing ttls (or the lack thereof). "}}