-
-
Notifications
You must be signed in to change notification settings - Fork 453
Cache is not available in cross script execution #836
-
Hello,
We have one common file that is included in every execution say common.php with following code
common.php
$InstanceCache = Phpfastcache\CacheManager::getInstance('files');
Phpfastcache\CacheManager::setDefaultConfig(new Phpfastcache\Config\ConfigurationOption([
"path" => "/tmpcache/",
"defaultTtl" => 2629746
]));
from one file I set cache say, file1.php that includes common.php like
$cachedItem = $InstanceCache->get('test_key');
$cachedItem->set('test_data');
$InstanceCache->save($cachedItem);
Now I want to access that cached data in file2.php that includes common.php like.
$cachedItem = $InstanceCache->get('test_key');
But I get empty item as $InstanceCache is a new fresh instance,
Any views on this?
### We want cached data to be accessed on cross script execution, as for example we have same product listing fetched from database in separate pages, so If I visit first page, it should be fetched and cached, again I visit second page, data should be fetched from cache.
Your support is appriciated.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions
It's because you call CacheManager::setDefaultConfig
after building your cache instance.
using CacheManager::setDefaultConfig
is useful if you have multiple cache pool instances.
In your case you can do the following:
$InstanceCache = Phpfastcache\CacheManager::getInstance('files', new \Phpfastcache\Config\ConfigurationOption([
"path" => "/tmpcache/",
"defaultTtl" => 2629746
]));
Replies: 2 comments 1 reply
-
It's because you call CacheManager::setDefaultConfig
after building your cache instance.
using CacheManager::setDefaultConfig
is useful if you have multiple cache pool instances.
In your case you can do the following:
$InstanceCache = Phpfastcache\CacheManager::getInstance('files', new \Phpfastcache\Config\ConfigurationOption([
"path" => "/tmpcache/",
"defaultTtl" => 2629746
]));
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks, It helps!
Beta Was this translation helpful? Give feedback.
All reactions
-
And please read carefully the WIKI and the DOCS. You can also look at the way I wrote the tests too. There's many documentation you can use to implement Phpfastcache.
Beta Was this translation helpful? Give feedback.