Invision Community 4: SEO, prepare for v5 and dormant account notifications By Matt Monday at 02:04 PM
ossipetz Posted December 22, 2017 Posted December 22, 2017 Hello We are trying to add some caching for our widget that shows the users that are online on rocket.chat. There are features in \IPS\Widget to allow caching but it seems the minimal time is 300 seconds - and we would like some cache but a shorter period. So we read the cache docs and looked at other widget and got it almost working. The cache seems to work fine, but only upon refresh the "lang" template parts are properly replaced: {lang="block_tfRocketChatWhosOnline"} When the cache is expired and the content is refreshed: When another refresh is done and the cache is hit: The sources / logic for the cache is here: https://github.com/tolkienforum/tfrocketchat/blob/master/widgets/tfRocketChatWhosOnline.php#L135 The logs show the content created and read from the cache seems to be the same: It is a mystery to me how this is possible - is there some initialization needed to have these language id's available? Both times the "render" function returns the html from the template or the cache - I don't get what causes the rendering to not know the translations. I'll also upload the current build of the application and the widget. Any hints are welcome! tfrocketchat-1.2.5.tar
Adriano Faria Posted December 22, 2017 Posted December 22, 2017 Minimal is 60. Not sure it will help:
ossipetz Posted December 22, 2017 Author Posted December 22, 2017 well that minimum might differ. it seems its read from the database settings ibf_core_sys_conf_settings.widget_cache_ttl which is 300 for me. Haven't found that setting in the admin panel :-/ We added that call to parseOutputForDisplay: https://github.com/tolkienforum/tfrocketchat/commit/16a2a35e2aff8eca794d2cb61a8eeaa9fc1e67be It now works! The cached string contains the replaced translations not the uuids/hashes anymore. Thanks for the link! I still don't understand why the first attempt worked before and only the second did not. Or what code replaced the language hashes before. Funny thing.
Adriano Faria Posted December 22, 2017 Posted December 22, 2017 Just now, ossipetz said: Haven't found that setting in the admin panel ACP -> System-> Advanced Configuration -> Cache sidebar, header and footer blocks.
ossipetz Posted December 22, 2017 Author Posted December 22, 2017 oh! there it is well the 300s setting is ok for me for the topics and posts and all cached system widgets - not quite happy with this one for all setting. the widgets differ quite a bit. so I'll keep my own rhythm for now. But good to know where it is in case we adopt this mechanism in the future. Thanks again!
newbie LAC Posted December 23, 2017 Posted December 23, 2017 Hello, 7 hours ago, ossipetz said: I still don't understand why the first attempt worked before and only the second did not. Or what code replaced the language hashes before. Funny thing. Language hashes are not constant and changes every time. Example <?php require_once 'init.php'; \IPS\Dispatcher\External::i(); $group = \IPS\Member\Group::load(4); print 'Group name is ' . $group->name; I resfresh the page In you cache stored old hashes. Why hashes? Because \system\Widget\Widget.php /** * Get HTML using the template (language strings not parsed) * * @return string */ public function output()
ossipetz Posted December 23, 2017 Author Posted December 23, 2017 Ahh I see. I tried manually calling the title and description functions in the Widget to have the translations on that stack - no luck. I assumed these where some hashes of the text and would survive. But now the behaviour makes sense. Thanks for the explanation! BTW: adding the cache to the widget did improve the page load times quite a bit
Recommended Posts
Archived
This topic is now archived and is closed to further replies.