Cache jak zjistim cas generovani informaci v cachi
Upozornění: Tohle vlákno je hodně staré a informace nemusí být platné pro současné Nette.
- ondra310
- Člen | 25
Zdravim,
dotaz, nactu si cache pomoci load. Pokud je cache uspesne nactena, jsem schopny nejak zjistit informaci o case, kdy byla cache generovana?
$cacheLoaded = $this->cache->load($cacheKey);
if ($cacheLoaded) return $cacheLoaded;
Kde
$this->cache = $cache = new \Nette\Caching\Cache($this->cacheStorage,$section);
Jde mi o to, ze bych potreboval informovat uzivatele o tom, jak stare jsou
informace v cachi. Je mozne, ze z nejakeho duvodu bude chtit informace novejsi
i kdyz na ne bude muset cekat delsi dobu.
Jedna se mi o to, jestli si mam jeste nekde bokem uchovat informaci
o poslednim case generovani cache, nebo jsem neco prehledl v API a umoznuje mi
to primo cache.
Pouzivam Nette 2.2.6.
Diky za pripadne nakopnuti.
- h4kuna
- Backer | 740
Já o ničem nevím.
Udělal bych si objekt.
<?php
class CacheData
{
private $data;
private $time;
public function __construct($data)
{
$this->data = $data;
}
public function getData()
{
return $this->data;
}
/** @return \DateTime */
public function getTime()
{
return $this->time;
}
public function __sleep()
{
if ($this->time === NULL) {
$this->time = new \DateTime;
}
return ['data', 'time'];
}
}
?>
Použití by bylo obalit data při uložení.
<?php
$this->cache->save($cacheKey, new CacheData($data));
?>