I have a SettingsSiteTable object with the following method for reading settings in the database and storing the results in a cache.
// GET ALL CONFIG SETTINGS
function getConfigs(){
if(($settings_site = Cache::read($this->key)) === false) {
$settings_site = $this->find('list', [
'keyField' => 'key',
'valueField' => 'value'
])->toArray();
Cache::write($this->key, $settings_site, 'settings');
}
return $settings_site;
} // END GET CONFIGS FUNCTION
$this->key is 'SettingsSite' and there appears to be no issue with that. I have also added use Cake\Cache\Cache to the table object file.
My cache config in the app.php file is as follows:
'Cache' => [
'default' => [
'className' => 'File',
'path' => CACHE,
],
'settings' => [
'className' => 'File',
'duration' => '+6 hours',
'path' => CACHE . 'settings/',
],
'_cake_core_' => [
// ...
],
'_cake_model_' => [
// ...
],
],
The cache appears to save successfully. I am able to view the cache file located at tmp/cache/settings/settings_site (not sure what the file extension is)
However, if I change the data in the database and refresh the page, the updated information is displayed meaning it is not reading from the cache correctly and it is re-querying the results.
What am I doing wrong? I got this code directly from the 3.X Cookbook: Writing to a Cache