(dev/core#174) civicrm_cache - Allow storage of binary data #12354
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
In working on a PSR-16 provider based on the
civicrm_cache
table, the compliance test suite revealed thatcivicrm_cache.data
was unable to store binary information. The cache is more useful if it can store binary data...Before
civicrm_cache.data
is a MySQLlongtext
column storing the output ofserialize($data)
.After
civicrm_cache.data
is a MySQLlongtext
column storing the output ofbase64_encode(serialize($data))
(or, if you've just upgraded, possiblyserialize($data)
).Technical Details
serialize
format is not designed for transmission over strictly textual media. It's meant to differentiate among PHP data-types(egarray
vsstring
vsint
). If astring
has binary content, then it's still binary content.serialize()
andbase64_encode()
are quite distinctive. Serialize makes heavy use of punctuation (;:{}
), whereas base64 is dense alphanumeric (a-zA-Z0-9+/
). We use this to pre-emptively deal with any weird edge-cases mixing new logic with old content (e.g. reading cached data in the old format in a pre-upgrade environment).