This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component
Nicolas Grekas b22a58449c feature #35362 [Cache] Add LRU + max-lifetime capabilities to ArrayCache (nicolas-grekas)
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
-------

48a5d5e8a9 [Cache] Add LRU + max-lifetime capabilities to ArrayCache
2020-01-27 11:48:06 +01:00
..
Asset Merge branch '5.0' 2020-01-04 15:20:45 +01:00
BrowserKit Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Cache feature #35362 [Cache] Add LRU + max-lifetime capabilities to ArrayCache (nicolas-grekas) 2020-01-27 11:48:06 +01:00
Config Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Console feature #35402 [Console] Set Command::setHidden() final for adding default param in SF 6.0 (lyrixx) 2020-01-27 11:27:10 +01:00
CssSelector Merge branch '5.0' 2020-01-04 15:20:45 +01:00
DependencyInjection Merge branch '5.0' 2020-01-21 09:44:52 +01:00
DomCrawler Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Dotenv Merge branch '5.0' 2020-01-08 18:33:57 +01:00
ErrorHandler Improve displaying anonymous classes 2020-01-26 14:13:42 +01:00
EventDispatcher Merge branch '5.0' 2020-01-10 22:57:55 +01:00
ExpressionLanguage Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Filesystem Merge branch '5.0' 2020-01-21 09:44:52 +01:00
Finder Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Form feature #35205 [Form] derive the view timezone from the model timezone (xabbuh) 2020-01-07 20:12:15 +01:00
HttpClient feature #35407 [HttpClient] collect the body of responses when possible (nicolas-grekas) 2020-01-22 08:06:55 +01:00
HttpFoundation Fix CS 2020-01-10 09:15:23 +01:00
HttpKernel Improve displaying anonymous classes 2020-01-26 14:13:42 +01:00
Inflector Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Intl Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Ldap Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Lock Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Mailer Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Messenger Improve displaying anonymous classes 2020-01-26 14:13:42 +01:00
Mime Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Notifier Merge branch '5.0' 2020-01-08 18:33:57 +01:00
OptionsResolver Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Process Merge branch '5.0' 2020-01-09 10:56:45 +01:00
PropertyAccess Merge branch '5.0' 2020-01-04 15:20:45 +01:00
PropertyInfo Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Routing Merge branch '4.3' into 4.4 2020-01-08 18:29:02 +01:00
Security minor #35447 [Security] suggest a non-deprecated function replacement (xabbuh) 2020-01-23 11:58:55 +01:00
Serializer Added scalar denormalization in Serializer + added scalar normalization tests 2020-01-13 11:50:29 +03:00
Stopwatch Merge branch '5.0' 2020-01-04 15:20:45 +01:00
String Merge branch '5.0' 2020-01-21 08:39:56 +01:00
Templating Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Translation Merge branch '5.0' 2020-01-21 09:44:52 +01:00
Validator Merge branch '5.0' 2020-01-21 09:44:52 +01:00
VarDumper Improve displaying anonymous classes 2020-01-26 14:13:42 +01:00
VarExporter Merge branch '5.0' 2020-01-04 15:20:45 +01:00
WebLink Merge branch '5.0' 2020-01-04 15:20:45 +01:00
Workflow [Workflow] Added a way to not fire the annonce event 2020-01-13 14:50:42 +01:00
Yaml Merge branch '5.0' 2020-01-21 12:13:09 +01:00