b22a58449c
This PR was merged into the 5.1-dev branch.
Discussion
----------
[Cache] Add LRU + max-lifetime capabilities to ArrayCache
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes
| Deprecations? | no
| Tickets | Fix https://github.com/orgs/symfony/projects/1#card-30686676
| License | MIT
| Doc PR | -
In https://github.com/symfony/symfony/pull/32294#issuecomment-508067745, @andrerom writes:
> if you plan to expose use of ArrayAdapter to a wider audience you should probably also add the following features to it:
> - max item limit to avoid reaching memory limits
> - own (very low, like default 100-500ms) TTL for in-memory caching, as it's in practice stale data when used in concurrent scenarios
>
> If you want to be advance you can also:
>
> - keep track of use, and evict cache items based on that using LFU when reaching limit
> - in-memory cache is domain & project specific in terms of how long it's somewhat "safe" to keep items in memory, so either describe when to use and not use on a per pool term, or allow use of pool to pass in flags to opt out of in-memory cache for cases developer knows it should be ignored
This PR implements these suggestions, via two new constructor arguments: `$maxLifetime` and `$maxItems`.
In Yaml:
```yaml
services:
app.lru150_cache:
parent: cache.adapter.array
arguments:
$maxItems: 150
$maxLifetime: 0.150
framework:
cache:
pools:
my_chained_pool:
adapters:
- app.lru150_cache
- cache.adapter.filesystem
```
This configuration adds a local memory cache that keeps max 150 elements for 150ms on top of a filesystem cache.
/cc @lyrixx since you were also interested in it.
Commits
-------
|
||
---|---|---|
.. | ||
Asset | ||
BrowserKit | ||
Cache | ||
Config | ||
Console | ||
CssSelector | ||
DependencyInjection | ||
DomCrawler | ||
Dotenv | ||
ErrorHandler | ||
EventDispatcher | ||
ExpressionLanguage | ||
Filesystem | ||
Finder | ||
Form | ||
HttpClient | ||
HttpFoundation | ||
HttpKernel | ||
Inflector | ||
Intl | ||
Ldap | ||
Lock | ||
Mailer | ||
Messenger | ||
Mime | ||
Notifier | ||
OptionsResolver | ||
Process | ||
PropertyAccess | ||
PropertyInfo | ||
Routing | ||
Security | ||
Serializer | ||
Stopwatch | ||
String | ||
Templating | ||
Translation | ||
Validator | ||
VarDumper | ||
VarExporter | ||
WebLink | ||
Workflow | ||
Yaml |