• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Caching contents of a sidebar block/widget

SneakyDave

Well-known member
#1
I have a widget that I want to cache the contents of to save on db requests. Is there is good place to find out how to do that, or a good resource that helps explain any best practices to use?

I was looking at Widget Framework, but that looks like it's more of an all-in-one cache solution just for it's own widgets, so I don't think I need it that complicated, but who knows?
 

Chris D

XenForo developer
Staff member
#7
Once it's in the cache, it's in there permanently. So, you first of all need to ensure that you take care of cache invalidation yourself. Second of all you also should unset any data on add on uninstall (just set false as the value).
 

Snog

Well-known member
#8
While I'm sure you wouldn't do it, I want to throw this out there. And @Chris D please correct me if I'm wrong.

The simple cache is not an infinite cache and can run out of room, so don't store huge amounts of data in there. I think it's best suited to small portions of data that would require many database reads, or a larger amount of time to compile.
 

Chris D

XenForo developer
Staff member
#11
The cache is a value which is serialised into a field inside the xf_data_registry table. The field is a BLOB which is around 16MB IIRC.

That's a considerable chunk of data. But yeah certainly not infinite by any means. That's why I said make sure you remove it on add on uninstall and certainly only cache what you need. It would take some effort to generate that amount of data.

User specific data for example would be better cached in the user's session.