Transient API key length could result in uncacheable data
|Reported by:||archon810||Owned by:|
I was just writing a caching layer for some plugin code using the Transient API and found that while caching was created, it was immediately discarded and re-cached. Upon further examination, I found that the transient key was different for the data itself compared to the timeout key. Specifically, the transient timeout key was longer due to the presence of the word "timeout" in it and was running into the MySQL key length limit of 64 characters, getting silently truncated.
Therefore, the key for the timeout was different than the key for the data, resulting in both rows being deleted every time get_transient() is called.
A solution would involve checking for the key length and possibly truncating the data key so that it wouldn't truncate the timeout key, but this solution could be confusing to the plugin writer who is expecting a certain key.
Sorry if I was confusing in describing the bug. tl;dr: transient key and transient timeout could end up being different and prevent caching from working.
Change History (3)
comment:2 in reply to: ↑ description @solarissmoke — 5 years ago
- Component changed from Cache to Database
- Keywords dev-feedback added; transient caching removed