[wp-trac] [WordPress Trac] #30430: WP_Object_Cache does not properly cache objects nested in arrays
WordPress Trac
noreply at wordpress.org
Fri Nov 21 00:17:32 UTC 2014
#30430: WP_Object_Cache does not properly cache objects nested in arrays
--------------------------+-----------------------------
Reporter: jamesgol | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Cache API | Version: trunk
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
I noticed on a plugin that cached data wasn't coming out the way it was
inserted. What was happening is that it was an array of objects. The
code would then go and change the original data and the data in the cache
is changed. I would expect data retrieved from the cache to be exactly
the same as what was inserted.
To make sure there was minimal performance impact I did some tests and the
test script is attached. Initially I thought
unserialize(serialize($data)) would be a good route, but it was twice as
slow as rolling your own solution. I tried numerous methods and the
function I initially build was always the fastest.
The transient/option table doesn't have this problem because it calls
maybe_serialize.
Another way to fix this would be to call maybe_serialize on the set, and
maybe_unserialize on a get but that would spread the cost to both
functions and I think it is better to have the set be slightly more
expensive than having every set and get take slightly longer.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/30430>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list