Hello, I'm looking for clarification on using cache_get/set. The normal rule of thumb seems to be a bit different than the docs: http://api.drupal.org/api/function/cache_set/7

Rule of thumb is that with cache you can lose your data at any moment.
Rule of thumb is that variable_get/set and custom tables if for persistent data.

No problem when the temporary data does not need to be shared with multiple users, but when the data does need shared, one needs to do custom tables, variable_get/set or cache_get/set (any other options?).

The API states, "CACHE_PERMANENT: Indicates that the item should never be removed unless explicitly told to using cache_clear_all() with a cache ID." The table column states "expire A Unix timestamp indicating when the cache entry should expire, or 0 for never." And unless your module implements hook_flush_caches(), the data will not be flushed when a user clicks "clear cache". I also see a handful of functions that call cache_clear_all() with the finer control of passing options. This seems to imply that a developer can have a bit more control over data loss than "any moment".

There are a few catches,
It looks like the core bins may or may not expire automatically regardless of CACHE_PERMANENT?
Is hook_flush_caches() needed for a custom bin, or only to have the custom bin flush automatically - I tried setting in bin "cache_mobwrite" and the table was not created?

Thanks,

Comments

tomdavidson’s picture

Thanks to dimitrig01.

You can control how short of life the var should have in cache, but you can not control how long it should last.
i.e. you can say "it sholudn't last longer than 10 minutes" but you can't say "it should last longer than 10 minutes"

This does not seem clear from the API docs.