Jump to content

Custom cache in widget, weird behaviour of translations


ossipetz

Recommended Posts

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:

image.png.4b2b105b63c5d027b5d7233feb8bba45.png

When another refresh is done and the cache is hit:

image.png.d2ad27ac479701d62102d6663c9c2ed2.png

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:

image.thumb.png.ac352753fafde4797dba463145d9305c.png

 

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

Link to comment
Share on other sites

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. :rofl:
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.

Link to comment
Share on other sites

oh! there it is :ph34r:

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! :thumbsup:

Link to comment
Share on other sites

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

hashes.gif.5cafa8a0cb08598ebad04d3c2983468b.gif

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()

 

 

 

Link to comment
Share on other sites

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 :thumbsup:

http_loadtime-day.png.73f5d36149b751d4e27d6d02c6ba5f9d.png

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...