This puts a very large amount of data in memory and, if the object cache is just PHP's memory, can overwhelm PHP. Another approach might be to store the post IDs, then do a get_posts or WP_Query with suppress_filters = false and specify the specific IDs, which is another query but a very optimised one.
We generally store arrays of whole post objects in object cache, like below…
This puts a very large amount of data in memory and, if the object cache is just PHP's memory, can overwhelm PHP. Another approach might be to store the post IDs, then do a
get_posts
orWP_Query
withsuppress_filters = false
and specify the specific IDs, which is another query but a very optimised one.