Closed kelunik closed 6 years ago
@kelunik hi, I can help you with this. Can you just describe how you see it ?
@zhikiri Awesome! For limiting the number of items in the cache (not its exact size), it just needs a few small changes:
https://github.com/amphp/cache/blob/d6ab81ce35019b0fd84ca6d665fd4817bfd11701/lib/ArrayCache.php#L89
Here it needs to unset()
the key before setting it, to make sure it's at the end of the array. If there's a $maxSize
and the size of the array is larger than $maxSize
, it needs to shift the first item in the array. That'll give us a LRU implementation.
@kelunik Got it.
@kelunik here is the PR for this https://github.com/amphp/cache/pull/5
Resolved via #5.
We should add
$maxSize
toArrayCache
or provide a second implementation ofArrayCache
that allows for such an option to limit the size of the cache.amphp/dns
is one component that potentially benefits from such an option to limit the cache size, otherwise the cache might grow indefinitely if a client always requests new hostnames and they have a high TTL.