XF 2.2 Any current recommended way of caching finder results?

Kevin

Well-known member
Is there a best practice, or at least a current recommended way, of caching finder results?

There are two places where I'd like to cache finder results; first for displaying results in a widget and then on it's own route for displaying the full results paginated. The add-ons in question are already up & running and I've got the widgets working fine and the dedicated route pages are working fine, I'm just working on cleaning up the code a bit and would like to explore caching options.

There's the below from @Ralle; is that or similar what other folks are using?
 
We don't really support the concept of serving entities/collections from a cache. (In theory you could do it, but it's probably important that the entities are detached as the cached entities may be outdated, which may cause issues depending on what the request ends up doing.)

I think generally speaking, we'd generally say that the best approach is to cache the result IDs so that the latest versions can be fetched efficiently on demand.

Your use case actually sounds somewhat similar to the search forums concept, and that actually has 2 levels of caching. First we do an "over fetch" based on the search criteria and then, from those, we cache enough results that reflects an individual user's set of permissions. (We still check that they can view things and if something changes in the cache window, a page may show slightly fewer results, but that's pretty incidental in the grand scheme of things.)
 
Thanks, @Mike, for the info. That makes sense about not caching the actual entities; it's a scenario that likely doesn't happen in the wild often but would still need to be taken into account.

I'll take a look at how the search forums do its caching. (y) Caching at the user level is likely more than what these add-ons need but it may be worth figuring out now so I have the code handy for other stuff in the future. :)
 
Yeah. I guess an entity allows you to set values and save. If the entity was stale you would override the version in the database. Buut if you know what you’re doing, this utility function I wrote is very nice. I use it myself.

it once again proves how flexible XF is. I love it.
 
Back
Top Bottom