Register "short" and "long" cache services
authorTim Otten <totten@civicrm.org>
Wed, 26 Sep 2018 23:19:45 +0000 (19:19 -0400)
committerTim Otten <totten@civicrm.org>
Fri, 28 Sep 2018 01:16:43 +0000 (21:16 -0400)
commit90cdaa0e0f6a93d54d9c2743bacd521b995c3f58
treed8ef7cdc20e64948a422a1a272558fdbde912ac9
parent56afc088f70196cddc7ea55dd05bc48a3cdc2999
Register "short" and "long" cache services

Overview
--------

This is an improvement for developer-experience when working with caches.
It reduces the amount of boilerplate required for core-code or
extension-code in a typical caching use-case.

Before
------

* To use a short-lived/latency-optimized cache (e.g. Redis or PHP array),
  you can work with the default cache instance (`Civi::cache('default')`.
* To use a long-lived/durability-optimized cache (e.g. Redis or SQL), there is no
  simple way or code. You must [register a custom cache service](https://docs.civicrm.org/dev/en/latest/framework/cache/#example-named-service).

After
-----

* All the above remains true. Additionally, you can request the `short` or `long` cache service.
* To use a short-lived/latency-optimized cache, you can use `Civi::cache('short')`. (`short` and `default` are synonmyms.)
* To use a long-lived/durability-optimized cache, you can use use `Civi::cache('long')`.

Comments
--------

* After this is approved, we should update the [dev docs for caching](https://docs.civicrm.org/dev/en/latest/framework/cache/).
* There's a bike-sheddy argument about the naming. I'd be willing to rename if there was a strong reason, but I don't really think
  there is a strong reason. This naming convention provides a simple dichotomy of `short` vs `long`.
CRM/Utils/System.php
Civi.php
Civi/Core/Container.php