function loadPrivileges($refresh=FALSE) {
$query = 'SELECT * FROM privileges WHERE ....';
return $db->exec($query,$args,$refresh ? -1 : 86400);
}
$results = $mapper->find(['foo > ?',5],null,3600);
$f3->merge('cache_tags.images',$f3->get('DB')->hash(), TRUE);
if ($f3->exists('cache_tags.images', $keys))
foreach($keys as $key)
\Cache::instance()->clear($key);
Thank you both!
$mapper->find($filter,$options,86400); // usual setting for front page
$mapper->find($filter,$options,0); // get a fresh set, but don't invalidate existing cached data
$mapper->find($filter,$options,-1); // get a fresh set + invalidate existing cached data
$f3->get('DB')->hash()
$customer=new DB\SQL\Mapper($db,'customers');
$customer->find($filter);
echo count($db->hash()); // 2 (one for the schema and one for the query)
$customer->getOrders();
echo count($db->hash()); // 3 (one for the schema, two for the queries)
// controller1
$mapper->find($filter1,$opts,$ttl);
$f3->merge('cache_tags.images',$f3->get('DB')->hash(),TRUE);
// controller2
$mapper->find($filter2,$opts,$ttl);
$f3->merge('cache_tags.images',$f3->get('DB')->hash(),TRUE);
// controller3
$mapper->find($filter3,$opts,$ttl);
$f3->merge('cache_tags.images',$f3->get('DB')->hash(),TRUE);
$db->exec($sql,$args,$ttl,'product'); // <-- tag that query as 'product' related
$mapper->find($filter1,$opts,$ttl,'product'); // idem
$mapper->find($filter2,$opts,$ttl,'product');
$mapper->find($filter3,$opts,$ttl,'product');
What you're saying is that we need to add an extra statement after each cached query. Right?
Not to mention that we need to persist the 'cache_tags' somehow.
Also it doesn't seem reliable as there could be some unexpected queries embedded in hash(), such as the ones induced by schema() or the onload() hook.
$f3->get('DB')->hash(TRUE);
$mapper->find($filter2,$opts,$ttl);
$f3->merge('cache_tags.images',$f3->get('DB')->hash(),TRUE);
What about giving a bit of control on the cache key suffix
$db->exec($sql,$args,[$ttl,'product']);
$mapper->find($filter1,$opts,[$ttl,'product']);
function getBaseCarPlateCodes(&$cacheTags)
{
$db = $this->getDb();
$sql = 'SELECT CodiceProvinciaID, cp_SiglaAuto ' .
'FROM BASE_CodiciProvince ' .
'ORDER BY cp_SiglaAuto';
$result = $db->exec($sql, null, 3600);
$cacheTags = $db->hash();
// var_dump($cacheTags);
return $result;
}
In fact, when being called from a web page, $cacheTags gets populated, when called from CLI it does not and the var_dump($cacheTags); shows that.$db->exec($sql, null, [3600,'customCacheTag']);
customCacheTag"
appended.customCacheTag
from the cache?
$results = $mapper->find(null,null,[3600,'customCacheTag']);
Cache::instance()->reset('customCacheTag');
company_id, company_name and :master_company_id
:
master_company_id
= 35. All 3 of them belong to a company whose ID = 35.
I have users D, E and F browsing each their own companies listing, identified by :
master_company_id
= 47
I have users G, H and I browsing each their own companies listing, identified by :
master_company_id
= 93
:
master_company_id
.
master_company_id = 35.
With the old system, I'd just go and delete the unique cache tag I earlier got by callling hash(). The first query cache would be reset for users A, B and C but nothing would happen to users D..I 's cached values.
How does this new system deal with this situation?
Does memcached (I use this cache storage) and / or F3 transparently store "
customCacheTag" + "something additional" I don't see, which still keeps those 3 queries cached each on its own?
Or do I end up overwriting each other's users groups cached content because
"customCacheTag" is taken "as is" and reused at every query call which specifies "customCacheTag" as tag?
Cache::instance()->reset('customCacheTag');
[globals]
DEBUG=3
CACHE="memcache=localhost:11211" | 2592000
...
[routes]
GET|POST /cache-tag-reset=<SNIP>\Helper\DebugClass->cacheTagReset
class DebugClass
{
...
public function cacheTagReset($f3, $params)
{
Cache::instance()->reset('nlo_car_plate_codes');
echo "Cache cleared\n";
}
}
class blahModel
{
function getCarPlateCodes($ttl = 7200)
{
$db = $this->getDB(); // this returns the PDO SQL instance
$sql = 'SELECT CodiceProvinciaID, cp_SiglaAuto ' .
'FROM BASE_CodiciProvince ' .
'ORDER BY cp_SiglaAuto';
$cacheTags = 'nlo_car_plate_codes';
return $db->exec($sql, null, [$ttl, $cacheTags]);
}
}
Cache cleared message.
However the key stays in memcached. The memcached screenshot actually has been taken after I have called the
Cache::instance()->reset('nlo_car_plate_codes');
Multiple times.
if (is_array($data))
foreach ($data as $key=>$val)
if (preg_match($regex,$key) &&
$val[1]+$lifetime<time())
memcache_delete($this->ref,$key);
nlo_car_plate_codes
cache tag being properly included (See my previous post).preg_match($regex,$key)
$val[1]+$lifetime<time()
$val[1]+$lifetime<time()