Memcache caching
How to calculate infinite expiration timestamp on Memcached 1.4.15
- open SSH connection to a web server (or where the Memcache is installed)
- run this command:
(sleep 1; echo "stats"; sleep 1; echo "quit";) | telnet localhost 11211 | grep 'time'
Example output:
STAT uptime 61335 STAT time 1676435743
- subtract the number after the uptime word from the number after the time word (e.g. 1676435743 - 61335 = 1676374408) and remember this number
How to calculate infinite expiration timestamp on Memcached 1.6.15
- No need to calculate because it's always 0.
How to determine key expiration
- open SSH connection to a web server (or where the Memcache is installed)
- run this command (replace slab_number_here with a positive number starting from 1; replace key_name_here with a key name you want to get info about):
(sleep 1; echo "stats cachedump slab_number_here 0"; sleep 1; echo "quit";) | telnet localhost 11211 | grep 'key_name_here'
Example output:
ITEM key_name_here [value_here b; timestamp_here s]
- if no data is returned try incrementing the number used in place of the slab_number_here text by 1 and running that command again
- if the number in place of the timestamp_here text the infinite expiration timestamp (either 0 or above calculated), then the key will never expire
- otherwise the key will expire at the given date/time
How to determine every key expiration/presence in the cache
- same steps as above, but omit the | grep 'key_name_here' part of the command
- iterate all slab numbers until no data between Escape character is '^]'. and END lines is returned
How to clean the cache
- if you have CentOS, then run the systemctl restart memcached.service command as the root user on the server
- when testing on the Memcache PHP extension (not Memcached PHP extension) please refresh Admin Console (the login will do) to initialize the Memcache, because otherwise, it won't work properly
Database caching
How to determine key expiration
- open the database (e.g. via phpMyAdmin)
- execute the SELECT LifeTime FROM SystemCache WHERE VarName = 'key_name_here'; database query
- if you'll get -1 it means, that the key won't automatically expire
- if you'll get a timestamp it means, that the key will expire after that time
How to determine every key expiration/presence in the cache
- same steps as above, but omit the WHERE VarName = 'key_name_here' part of the database query
How to clean the cache
- open the database (e.g. via phpMyAdmin)
- run the TRUNCATE SystemCache; database query in the
Actual tests
Testing clean install
- perform a clean install via the /core/install.php script
- confirm, that at the System Configuration installation step the Maximum Cache Duration (in days) setting has an initial value of 30
- change value to 25 and proceed with the install
- confirm, that after the installation was done the MaxCacheDuration setting in the /system/config.php has a value of 25
Testing an upgrade
- remove the $_CONFIG['Misc']['MaxCacheDuration'] = ...; line in the /system/config.php file
- open the /core/install.php script of the existing In-Portal installation
- on the Installation Maintenance screen:
- type root user login/password
- select the Upgrade In-Portal radio button
- press Continue
- perform the upgrade
- confirm, that after the installation was done the MaxCacheDuration setting in the /system/config.php has a value of 30
Testing "setCache"
Setup:
- clean the memory cache (see instructions above)
- change the value of the MaxCacheDuration setting in the /system/config.php file to the 25
- change the value of the CacheHandler setting in the /system/config.php file to the Memcache
Set without expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteCache('key_with_def_exp'); $application->setCache('key_with_def_exp', 'v1');
- confirm (see instructions above), that the "key_with_def_exp" key has an expiration of 25 days (from the time key was set via the "setCache" method call)
Set with expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteCache('key_with_exp'); $application->setCache('key_with_exp', 'v2', 3600);
- confirm (see instructions above), that the "key_with_exp" key has an expiration of 1 hour (from the time key was set via the "setCache" method call)
Set with infinite expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteCache('key_with_inf_exp'); $application->setCache('key_with_inf_exp', 'v2', 0);
- confirm (see instructions above), that the "key_with_inf_exp" key has an infinite expiration
Testing "addCache"
Setup:
- clean the memory cache (see instructions above)
- change the value of the MaxCacheDuration setting in the /system/config.php file to the 25
- change the value of the CacheHandler setting in the /system/config.php file to the Memcache
Add without expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteCache('key_with_def_exp'); $application->addCache('key_with_def_exp', 'v1');
- confirm (see instructions above), that the "key_with_def_exp" key has an expiration of 25 days (from the time key was set via the "addCache" method call)
Add with expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteCache('key_with_exp'); $application->addCache('key_with_exp', 'v2', 3600);
- confirm (see instructions above), that the "key_with_exp" key has an expiration of 1 hour (from the time key was set via the "addCache" method call)
Add with infinite expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteCache('key_with_inf_exp'); $application->addCache('key_with_inf_exp', 'v2', 0);
- confirm (see instructions above), that the "key_with_inf_exp" key an infinite expiration
Add won't overwrite:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->addCache('key_with_exp', 'v3', 86400); echo $application->getCache('key_with_exp');
- confirm, that both key value (that is shown on screen) and expiration (see instructions above) match $application->addCache('key_with_exp', 'v2', 3600); command executed above this test
Testing "setDBCache"
Setup:
- clean the database cache (see instructions above)
- change the value of the MaxCacheDuration setting in the /system/config.php file to the 25
- change the value of the CacheHandler setting in the /system/config.php file to the Fake
Set without expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteDBCache('db_key_with_def_exp'); $application->setDBCache('db_key_with_def_exp', 'v1');
- confirm (see instructions above), that "db_key_with_def_exp" key has expiration of 25 days (from the the time key was set via "setDBCache" method call)
Set with expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteDBCache('db_key_with_exp'); $application->setDBCache('db_key_with_exp', 'v2', 3600);
- confirm (see instructions above), that "db_key_with_exp" key has expiration of 1 hour (from the the time key was set via "setDBCache" method call)
Set with infinite expiration:
- replace code fragment between $application->Init(); and $application->Done(); in the /index.php file with this code:
$application->deleteDBCache('db_key_with_inf_exp'); $application->setDBCache('db_key_with_inf_exp', 'v2', 0);
- confirm (see instructions above), that "db_key_with_inf_exp" key has in infinite expiration
Testing internal caches expiration for Memcache
Setup:
- clean the memory cache (see instructions above)
- change the value of the MaxCacheDuration setting in the /system/config.php file to the 25
- change the value of the CacheHandler setting in the /system/config.php file to the Memcache
Populate cache:
- login to In-Portal admin console
- open any category record for editing (to populate master:StructureTree key)
- make some changes
- save changed record to the database (to set category serial key)
- visit the Front-End in another web browser tab (to populate master:template_mapping, master:cms_menu and master:domains_parsed keys)
Confirm, that:
- these keys have infinite expiration (the 1738250904 number might differ on your install):
- test
- site_serial:1738250904
- site_serial:1738250904:1:master:configs_parsed
- site_serial:1738250904:1:master:last_cache_rebuild
- site_serial:1738250904:1:master:StructureTree
- site_serial:1738250904:1:master:template_mapping
- site_serial:1738250904:1:master:cms_menu
- site_serial:1738250904:1:master:sections_parsed
- site_serial:1738250904:1:master:domains_parsed
- site_serial:1738250904:1:master:config_files
- all other keys have an expiration of 25 days (with a few seconds margin) relative to the time they're set
Testing internal caches expiration for DB cache
Setup:
- clean the memory cache (see instructions above)
- change the value of the MaxCacheDuration setting in the /system/config.php file to the 25
- change the value of the CacheHandler setting in the /system/config.php file to the Fake
Populate cache:
- login to In-Portal admin console
- open any category record for editing (to populate StructureTree key)
- make some changes
- save the changed record to the database (to set category serial key)
- visit the Front-End in another web browser tab (to populate template_mapping, cms_menu and domains_parsed keys)
Confirm, that:
- these keys have infinite expiration:
- configs_parsed
- last_cache_rebuild
- StructureTree
- template_mapping
- cms_menu
- sections_parsed
- domains_parsed
- config_files
- the keys, that end with _HotLimit (e.g. Topic_HotLimit) have 3600 expiration
- if some keys start with ShippingQuotes, then they should have 1 day expiration
Testing template fragment caching in Memcache has an expiration cap
Setup:
- clean the memory cache (see instructions above)
- change the value of the MaxCacheDuration setting in the /system/config.php file to the 25
- change the value of the CacheHandler setting in the /system/config.php file to the Memcache
Populate cache:
- login to the Admin Console
- go to the Configuration → Website → Advanced section
- enable the Enable Tag Caching system setting
- save changes
- open the Front-End
Confirm, that:
- site_serial:1738250904:1:parser_35334543 like keys (all numbers may vary) are present
- they have an expiration of 25 days (with a few seconds margin) relative to the time they're set (page, that was setting them on the Front-End was accessed)
Testing template fragment caching in Memcache can configure expiration
Setup:
- clean the memory cache (see instructions above)
- change the value of the MaxCacheDuration setting in the /system/config.php file to the 25
- change the value of the CacheHandler setting in the /system/config.php file to the Memcache
Populate cache:
- change <inp2:m_Cache key="prefix:lang;skip_var:t,page,per_page,sort_by"> line in the themes/advanced/platform/elements/header.elm.tpl template to <inp2:m_Cache key="prefix:lang;skip_var:t,page,per_page,sort_by" cache_timeout="3600">
- login to the Admin Console
- go to the Configuration → Website → Advanced section
- enable the Enable Tag Caching system setting
- save changes
- open the Front-End
Confirm, that:
- site_serial:1738250904:1:parser_35334543 like keys (all numbers may vary) are present
- they some of them now have an expiration of 1 hour (with a few seconds margin) relative to the time they're set (page, that was setting them on the Front-End was accessed)