Cache methods in 5.8
Permalink
Hi All
Can't I use these codes in 5.8:
Also global $c won't work in 5.8 ??
Rony
Can't I use these codes in 5.8:
Cache::delete($cached_block_pro, false); Cache::get($cached_block_pro, false); Cache::set($cached_block_pro, false, $Items);
Also global $c won't work in 5.8 ??
Rony
Isn't there anyone who can help me on this?
Did you take a look at the documentation?https://documentation.concrete5.org/developers/caching...
Hi Michele
Yes I've already looked into the documentation but cannot understand it from there. Can you point me to right direction.
Thanks
Yes I've already looked into the documentation but cannot understand it from there. Can you point me to right direction.
Thanks
First of all, you have to decide which cache you want to work with, "cache", "cache/request" or "cache/expensive" - seehttps://documentation.concrete5.org/developers/caching/overview... for a description
Here I'll assume that:
- you want to use the request cache;
- $cacheKey is the key of the cache
Next, if you are in a controller:
$app = $this->app;
else
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
And here's the code:
Is it more clear now?
Here I'll assume that:
- you want to use the request cache;
- $cacheKey is the key of the cache
Next, if you are in a controller:
$app = $this->app;
else
$app = \Concrete\Core\Support\Facade\Application::getFacadeApplication();
And here's the code:
$cache = $app->make('cache/request'); $cacheItem = $cache->getItem($cacheKey); if ($cacheItem->isMiss()) { $cacheItem->lock(); // The item is not in the cache: let's calculate its value and store it in $value $value = ...; $cache->save($cacheItem->set($value)); } else { $value = $cacheItem->get(); } // At this point $value is what you want
Is it more clear now?
Good answer - a couple of quick questions.
Aren't we supposed to be using \Core::make() instead of $app->make()?
Also I think this is now needed in v8 instead of the $cache-save() above?
It would be nice if this complexity was wrapped in the core instead...
Aren't we supposed to be using \Core::make() instead of $app->make()?
Also I think this is now needed in v8 instead of the $cache-save() above?
if (version_compare(\Config::get('concrete.version'), '8.0', '>=')) { $cache->set($list)->expiresAfter(60 * 60)->save(); // expire after 1 hour } else { $cache->set($list, 60 * 60); // expire after an hour (v7) }
It would be nice if this complexity was wrapped in the core instead...
\Core::make() is a wrapper of $app->make(), so the preferred way is to use $app directly (is a bit faster).
$cache->save($cacheItem);
is exactly the same as calling
$cacheItem->save();
but yes, I'd prefer this second sintax, so that you can use method chaining:
(PS: in your example, you are missing the "save" call at the line "$cache->set($list, 60 * 60);")
$cache->save($cacheItem);
is exactly the same as calling
$cacheItem->save();
but yes, I'd prefer this second sintax, so that you can use method chaining:
$cacheItem ->set($value) ->expiresAfter(60) ->save() ;
(PS: in your example, you are missing the "save" call at the line "$cache->set($list, 60 * 60);")
I'm using this:
But it says:
Argument 1 passed to Concrete\Core\Cache\Cache::save() must implement interface Psr\Cache\CacheItemInterface, array given, called in /home/c58/public_html/packages/autonav_rd/blocks/autonav_rd/view.php on line 35.
Thanks
$expensiveCache = \Core::make('cache/expensive'); $cacheObject = $expensiveCache->getItem($cached_autonav); if($cacheObject->isMiss()){ //get navigation $allNavItems = $controller->generateNav(); //create nav array $nav_class = Loader::helper('autonav_rd'); $nav_class->set_curr($c); $nav_class->create_nav_objs($allNavItems); $navItems = $nav_class->navItem; $expensiveCache->save($cacheObject->set($navItems)); }
But it says:
Argument 1 passed to Concrete\Core\Cache\Cache::save() must implement interface Psr\Cache\CacheItemInterface, array given, called in /home/c58/public_html/packages/autonav_rd/blocks/autonav_rd/view.php on line 35.
Thanks
Try adding right after the isMiss() and change the last line tofor however long you want to actually cache it.
$cacheObject->lock();
$cacheObject->set($navItems)->expiresAfter(60 * 60)->save(); // expire after 1 hour
Thanks for the clarification. It seems \Core::make() is usable, regardless of whether you are in a controller or not.
The way I am reading the overview doc (such as it is) the save is not needed for v7? Or is that just another incorrect part of that documentation?
> $studentCourseList->set($list, 300); // expire after 300 seconds
The way I am reading the overview doc (such as it is) the save is not needed for v7? Or is that just another incorrect part of that documentation?
> $studentCourseList->set($list, 300); // expire after 300 seconds
Core::make is deprecated. See:
https://documentation.concrete5.org/developers/appendix/deprecated-c...
https://documentation.concrete5.org/developers/appendix/deprecated-c...
I believe you, but after reading that twice I don't see \Core::make() mentioned anywhere?
Hmmm. Its so far deprecated its disappeared from the deprecated list.
Haha - got a good chuckle out of that one.
Guess someone should tell the cache overview documentation... thought those were going to be editable?
Add: NVM, it just appears that I get constantly logged out of both the documentation subdomains...
Guess someone should tell the cache overview documentation... thought those were going to be editable?
Add: NVM, it just appears that I get constantly logged out of both the documentation subdomains...
The documentation can be modified by everybody: just login and hit the Edit This Page button
Don't use global $c - replace with this before using it:
$c = \Page::getCurrentPage();
> Don't use global $c - replace with this before using it:
> $c = \Page::getCurrentPage();
Is this post related to this thread?
> $c = \Page::getCurrentPage();
Is this post related to this thread?
I've mentioned this into my main post though it is different topic. Thanks for the answer.
It was the second question in his post...
NEED YOUR HELP!!! OK I'm trying to convert the Hostco's Autonav Pro (5.6) add-on to 5.8 for my personal use. I've done most of the part but not sure why, it doesn't display the page name along with link. This is how it generate the html.
Can anyone help! I'm attaching the package here.
Thanks
<ol class="pronav_list pronav_list_dark pronav_list183 anp-nav-pos-default anp-drop-pos-default" id="pronav_list183"><li class=" nav-selected nav-path-selected nav-home nav-item-1"><a href="/" target="_self" class="nav-selected nav-path-selected nav-home nav-item-1"></a></li><li class=" nav-item-178"><a href="/" target="_self" class="nav-item-178"></a></li><li class=" nav-item-180"><a href="/" target="_self" class="nav-item-180"></a></li><li class=" nav-item-188"><a href="/" target="_self" class="nav-item-188"></a></li><li class=" nav-item-189"><a href="/" target="_self" class="nav-item-189"></a></li><li class=" nav-item-190"><a href="/" target="_self" class="nav-item-190"></a></li><li class=" nav-item-191"><a href="/" target="_self" class="nav-item-191"></a></li><li class=" nav-item-192"><a href="/" target="_self" class="nav-item-192"></a></li><li class=" nav-item-193"><a href="/" target="_self" class="nav-item-193"></a></li><li class=" nav-item-181"><a href="/" target="_self" class="nav-item-181"></a></li><li class=" nav-item-198"><a href="/" target="_self" class="nav-item-198"></a></li><li class=" nav-item-199"><a href="/" target="_self" class="nav-item-199"></a></li><li class=" nav-item-202"><a href="/" target="_self" class="nav-item-202"></a></li><li class=" nav-item-203"><a href="/" target="_self" class="nav-item-203"></a></li><li class=" nav-item-200"><a href="/" target="_self" class="nav-item-200"></a></li><li class=" nav-item-183"><a href="/" target="_self" class="nav-item-183"></a></li><li class=" nav-item-195"><a href="/" target="_self" class="nav-item-195"></a></li><li class=" nav-item-196"><a href="/" target="_self" class="nav-item-196"></a></li><li class=" nav-item-197"><a href="/" target="_self" class="nav-item-197"></a></li><li class=" nav-last nav-item-185"><a href="/" target="_self" class="nav-last nav-item-185"></a></li></ol>
Can anyone help! I'm attaching the package here.
Thanks
I don't think it's ok to publicly post the whole source code of a paid package, even if you did some work on it...
I really need this to be fixed. That's why put it here. If it is causing any issue, I can surely remove that.
Sure it is an issue: you are breaking the license! (seehttps://www.concrete5.org/marketplace/addons/auto-nav-pro/license/... )