Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Cache is not available in cross script execution #836

Answered by Geolim4
rahulradixweb asked this question in Q&A
Discussion options

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.

You must be logged in to vote

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

Comment options

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 
 ]));
You must be logged in to vote
1 reply
Comment options

Thanks, It helps!

Answer selected by rahulradixweb
Comment options

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.

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /