(dev/core#174) Forms/Sessions - Store state via Civi::cache('session')
authorTim Otten <totten@civicrm.org>
Thu, 29 Mar 2018 01:52:57 +0000 (18:52 -0700)
committerTim Otten <totten@civicrm.org>
Mon, 2 Jul 2018 05:08:23 +0000 (22:08 -0700)
commit19707a63a5e0ae58090803f3c7c162481515f69f
treedb8c63e09d123ad3d0b4c2a725a166876c76f3ca
parent3962e60cf1ee00c35058334faf50ed37db443138
(dev/core#174) Forms/Sessions - Store state via Civi::cache('session')

Overview
----------------------------------------

When using forms based on CiviQuickForm (specifically `CRM_Core_Controller`), `CRM_Core_Session`
stores form-state via `CRM_Core_BAO_Cache::storeSessionToCache` and `::restoreSessionFromCache`,
which in turn calls `CRM_Core_BAO_Cache::setItem()` and `::getItem()`.

However, using `CRM_Core_BAO_Cache::setItem()` and `::getItem()` means that all session state
**must** be written to MySQL.  For dev/core#174, we seek the **option** to store via
Redis/Memcache.

Before
----------------------------------------

* (a) Form/session state is always stored via `CRM_Core_BAO_Cache::setItem()` and `civicrm_cache` table.
* (b) To ensure that old sessions are periodically purged, there is special purpose logic that accesses `civicrm_cache`
  (roughly `delete where group_name=Sessions and  created_date < now()-ttl`).
* (c) On Memcache/Redis-enabled systems, the cache server functions as an extra tier. The DB provides canonical storage for form/session state.

After
----------------------------------------

* (a) Form/session state is stored via `CRM_Utils_CacheInterface`.
    * On a typical server, this defaults to `CRM_Utils_Cache_SqlGroup` and `civicrm_cache` table.
* (b) To ensure that old sessions are periodically purged, the call to `CRM_Utils_CacheInterface::set()` specifies a TTL.
    * It is the responsibility of the cache driver to handle TTLs. With #12360, TTL's are supported in `ArrayCache`, `SqlGroup`, and `Redis`.
* (c) On Memcache/Redis-enabled systems, the cache server provides canonical storage for form/session state.
CRM/Core/BAO/Cache.php
CRM/Core/Session.php
Civi/Core/Container.php