# Memcache caching
## How to calculate infinite expiration timestamp
1. open SSH connection to a web server (or where the Memcache is installed)
2. run this command:
```
lang=bash
(sleep 1; echo "stats"; sleep 1; echo "quit";) | telnet localhost 11211 | grep 'time'
```
Example output:
```
STAT uptime 61335
STAT time 1676435743
```
3. 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 determine key expiration
1. open SSH connection to a web server (or where the Memcache is installed)
2. run this command:
```
lang=bash
(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]
```
3. if no data is returned try incrementing the `slab_number_here` parameter by 1 and running that command again
4. if the number in place of the `timestamp_here` text matches the infinite expiration timestamp, then the key will never expire
5. otherwise the key will expire at the given date/time
# 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
# Actual tests
## TODO## How to clean the cache
1. if you have CentOS, then run the `systemctl restart memcached.service` command as `root` user on the server
# 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 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 `/core/install.php` script
# confirm, that at the `System Configuration` installation step the `Maximum Cache Duration (in days)` setting has initial value of `30`
# change value to `25` and proceed with install
# confirm, that after installation was done the `MaxCacheDuration` setting in the `/system/config.php` has value of `25`
## Testing an upgrade
# remove the `$_CONFIG['Misc']['MaxCacheDuration'] = ...;` line in the `/system/config.php` file
# open `/core/install.php` script of 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 installation was done the `MaxCacheDuration` setting in the `/system/config.php` has value of `30`
## Testing "setCache"
* config:
* change the value of the `MaxCacheDuration` setting in the `/system/config.php` file to the `25`
* set without expiration:
* replace code fragment between `$application->Init();` and `$application->Done();` in the `/index.php` file with this code:
```
lang=php
$application->deleteCache('key_with_def_exp');
$application->setCache('key_with_def_exp', 'v1');
```
* confirm (see instructions above), that "key_with_def_exp" key has expiration of 25 days (from the the time key was set via "setCache" method call)
* set with expiration:
* replace code fragment between `$application->Init();` and `$application->Done();` in the `/index.php` file with this code:
```
lang=php
$application->deleteCache('key_with_exp');
$application->setCache('key_with_exp', 'v2', 3600);
```
* confirm (see instructions above), that "key_with_exp" key has expiration of 1 hour (from the the time key was set via "setCache" method call)
## Testing "addCache"
* config:
* change the value of the `MaxCacheDuration` setting in the `/system/config.php` file to the `25`
* add without expiration:
* replace code fragment between `$application->Init();` and `$application->Done();` in the `/index.php` file with this code:
```
lang=php
$application->deleteCache('key_with_def_exp');
$application->addCache('key_with_def_exp', 'v1');
```
* confirm (see instructions above), that "key_with_def_exp" key has expiration of 25 days (from the the time key was set via "addCache" method call)
* add with expiration:
* replace code fragment between `$application->Init();` and `$application->Done();` in the `/index.php` file with this code:
```
lang=php
$application->deleteCache('key_with_exp');
$application->addCache('key_with_exp', 'v2', 3600);
```
* confirm (see instructions above), that "key_with_exp" key has expiration of 1 hour (from the the time key was set via "addCache" method call)
* add won't overwrite:
* replace code fragment between `$application->Init();` and `$application->Done();` in the `/index.php` file with this code:
```
lang=php
$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) matches `$application->addCache('key_with_exp', 'v2', 3600);` command executed above this test
**TODO**