XF 2.0 SimpleCache

Valhalla

Well-known member
Can SimpleCache be made user-specific in the following way?

$simpleCache['My/Addon']['map' . $visitor->user_id] = $myArray;

Does it get overwritten upon being set with the same name?

Does it / can it, get purged (except upon addon uninstall)?

EDIT:

Seems I can unset with:

$this->app->simpleCache()->deleteValue();

I think the answer is 'yes' to all.
 
Last edited:
We'd strongly discourage using the simple cache as a user-specific cache.

Every piece of data in the simple cache is stored in a single field in the registry. Certainly, for sites where the registry is stored in the database, it is possible to very quickly exceed the limits of that database field. The limit is essentially 16MB. It might seem like a lot, but with lots of users it's certainly not unfeasible for it to cause issues, plus other add-ons may be using the simple cache for other things that may leave you with even less space to work with.

Even if you don't exceed that limit or the registry is offloaded to an external cache, the data has to be loaded for all users on every page load, and that's just wasteful in terms of resource usage.

The best approach is what we do with various other user based caches, which is to load the data from the database when a user's session is created, and store it actually in the user's session. The benefit is that the data is available with only the cost of a single query when the user's session starts, only the data that is required is actually available and the data is automatically cleaned up when their session expires.
 
Top Bottom