MyBB Community Forums

Full Version: format_avatar caching issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
The format_avatar function caches the avatar on the first call. However the cache doesn't consider the max_dimensions parameter. Eg I use the function sometimes with a max dimension of "17x17" to display the avatar in a text, however on a page where the function is called before without (or with different) max dimensions the cache will contain the bigger image and return it which breaks my complete text.
I noticed this with one of my plugins too, had to read the function to figure out the issue. It caches the first call of the avatar. I don't think there is a reliable fix for this unless we remove the caching, is there? I simply coded/duplicated the function.
Maybe add a 3rd optional parameter set to true by default to turn on/off caching.
Simply don't use the cache if the max dimensions parameter is set to a different dimension than the setting or change the cache to
array("uid" => array("dimension" => "avatardata")); 
Instead of
array("uid" => "avatardata"); 
I'm having a similar issue with myAlerts and caching. I use format_avatar in global_intermediate with a custom max size, which then sets all avatars on the page to that size. Which kind of sucks. A third parameter to prevent caching would be very useful.
A third parameter wouldn't fix the issue at all - if I call the function at global_start with a max_dimension of 1x1 without the parameter every mybb avatar would be shown as 1x1. There should be some automated process (either disable it automatically or cache the different t sizes).
It would fix it if people calling it in global_start remembered to use the parameter. I don't see a problem with caching different sizes though.
(2014-12-21, 07:23 PM)JonesĀ H Wrote: [ -> ]if I call the function at global_start with a max_dimension of 1x1 without the parameter every mybb avatar would be shown as 1x1

But that's exactly the point of changing the parameter - to prevent caching only whenever needed. Not only reading from the existing cache, also writing to it.

I agree it's not the best thing we can do, but I don't think that disabling the cache automatically depending on a max dimensions setting is a better solution. What if the custom dimensions are the only ones called on the page? Then it wouldn't cache the avatars even though it wouldn't disturb anything else.

Not sure what you mean by your 2nd solution.
any ideas for fix this problem now?
You shouldn't experience any issues in a default MyBB installation so I don't see the hurry.
Pages: 1 2