MyBB Community Forums

Full Version: Lets Talk Cache Size
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I hate to admit it, but I do not even understand exactly what is in the balance when considering a limit on the amount of data that a plugin should store in its cache entry. I assume that at some point it cuts into the memory available to the server, but having no experience with those things, I don't really know what a good top limit is for the forum as a whole-- if I did that would help to think about what I will be adding to the total cache size by my inclusions.

Does anyone care to share any wisdom or general guidelines on how much info a plugin should store in its cache entry?

Thanks in advance.
Ideally, you should cache anything that doesn't change often. For instance, plugin version, usergroups, forums. Anything that changes with any sort of frequency shouldn't really be in the cache.

The default setup in MyBB stores the datacache in the database anyway - and I'm willing to bet most users don't change it. Only those who understand what a cache is and/or those who need abetter caching mechanism likely change it.
(2013-09-14, 09:55 AM)Euan T Wrote: [ -> ]Anything that changes with any sort of frequency shouldn't really be in the cache.

This is what I m concerned about as well. So, do you think I would be better off dumping to my own table and retrieving it (so it doesn't load up with the rest of the cached info EVERY load) rather than using the MyBB cache for, say, the user name cache in MentionMe?

I just want to do what is best . . .

Thanks for your answer. Things like this I get confused and Google didn't really help much this time. Smile
Storing the username cache in the built in datacache table sounds like a bad idea to me due to how the cache's structure works (and the fact you'd be fetching every single username in the cache on each call, which will use a fair bit of memory on large boards). I'd create a new table and I'd give the usernames an index too to speed things up a bit. Unless anybody else has a better solution of course.
I'll be looking at it closely. Thanks for the ideas. Smile
Caching a username for that sort of need is IMHO an overkill on large boards. As Euan mentioned (from what my knowledge says) is correct. Query it if needed. Most of the times though (if it's a user sided part) you can even fetch username using globals. But anyway, a query is recommended generally (from my point of view). Also not to mention if there are boards which permits username changes (which majority of them does) you'd need to add a hook at username change and also replace the username stored in the cache I guess. It's not worth it I guess.
There are ways that I can reduce the amount of information I am storing and I am always looking for those.

When it comes to using the cache, I have no excuse other than I learned of it and started using it immediately like a child with a new toy. The info I store is not large and I don't feel too worried about it, but in the very near future I think I will be replacing the caching code with something lighter and custom.

That is really why I made the thread; your opinions are valuable (I don't have any friends IRL that do this).
Joining the discussion just to listen to your suggestions if you have some about something I'm working on. I always wanted to have something like an automatic contests manager and the idea is very simple yet basic: you post a new thread in a specific Forum (the "contest"), you fill some inputs with redeem and/or promotional codes and you set up an end date for the event. When the contest expires, the codes are automatically and randomly delivered to random users participating to the contest.

The missing "puzzle's piece" of this system is whether to store the promo codes, the expiry date and the tid of the thread into the datacache table or to create a standalone table. I'm not sure what's the most efficient method I should use: the built-in cache is very easy to use but it requires a bit of more processing I guess.
@shade due to the discussion here, I am working on a very simple class-based individual plugin cache. If you're interested, I can post the code when I am done.

The goal is to make it as easy to use as the MyBB core datacache, but not have it preemptively load anything. So, on first read it will fill in all cache entries and subsequent calls will be query-free, but if you don't call it the memory need not be allocated at all.

It shouldn't be that hard, I am thinking.
That seems really interesting. Sharing would be awesome, thanks!
Pages: 1 2