Implement CRM_Utils_Cache_ArrayDecorator
authorTim Otten <totten@civicrm.org>
Mon, 21 Jan 2019 10:06:21 +0000 (02:06 -0800)
committerTim Otten <totten@civicrm.org>
Wed, 30 Jan 2019 00:47:08 +0000 (16:47 -0800)
commit5876627a64fc398e3f31306d18892edb69ffd18c
treede68c0f3c733c4e08655793f5840fc3a1fc1354f
parent3768d7a07ff87848f87dc2aed605a71ec8143e27
Implement CRM_Utils_Cache_ArrayDecorator

This allows you to put a static array in front of another cache.  It is the
same basic idea as CRM_Utils_Cache_Tiered, but it's optimized for a typical case
where you only want one front-cache.

Based on some naive benchmarking (performing several trials with a few
thousand duplicate reads over the same cached data), this basically cut the
read-time in half.  The following is pretty representative of the results:

```
Redis-only cache               write=0.1044s   read=1.3266s
2-Tier (ArrayCache+Redis)      write=0.1189s   read=0.3765s
Decorated-Redis cache          write=0.1105s   read=0.1505s
```

See also: https://gist.github.com/totten/6d6524be115c193e0704ff3cf250336d

Note: To ensure that TTL data is respected consistently regardless of how
the tiers behave and the order in which they are used, the TTL/expiration
must be stored extra times.
CRM/Utils/Cache/ArrayDecorator.php [new file with mode: 0644]
tests/phpunit/E2E/Cache/ArrayDecoratorTest.php [new file with mode: 0644]