[wp-hackers] Transient key best practice

Micky Hulse mickyhulse.lists at gmail.com
Mon Sep 9 19:38:26 UTC 2013


I'm writing a class that gets a JSON response from YouTube's API and
caches the parsed data into a WP transient.

I was tentatively planning on creating transient keys that look like:



1. "namespace_youtube" = Make sure I don't stomp on other keys and
easier to find.

2. "playlist_or_user" = Will be either a playlist ID or a username.

3. "cache_time" = How long to cache this transient.

4. "number_of_items" = Number of videos that were cached in this transient.

5. "|||" = Just an easy delimiter for me to search on if I need to
get/parse transient keys.


I want the ability to cache multiple different types of YouTube API
calls and have them be cached based on playlist ID or username, how
long it was it's supposed to be cached for and the number of items
cached. In other words, there might be times where I need to request
the same playlist but vary it's output by the cache time and number of
items requested from the API.


Based upon my goal, does the above transient key naming convention make sense?

What's common transient caching naming practice for situations like I
describe above?

For when it comes to transients, is there a way to have simpler
transient key (just simply "namespace_youtube", for example) naming
convention yet vary, and have the ability to access, the data stored
in that transient?

Please let me know if I need to clarify my questions.


More information about the wp-hackers mailing list