Open XedinUnknown opened 7 years ago
We just ran across this issue at work.
I will have an attempt at rewriting some documentation soon.
Any help would be appreciated.
Feedback / thoughts @tedivm @XedinUnknown .
Thanks.
The issue we ran across was how to actually change invalidation methods.
The documentation is completely wrong in this regard.
<?php
$item = $pool->getItem('Test');
// Get the data from the cache using the "Invalidation::OLD" technique for
// dealing with stampedes
$userInfo = $item->get();
$userInfo->setInvalidationMethod(Stash\Invalidation::OLD);
// Check to see if the cache missed, which could mean that it either didn't
// exist or was stale. If another process is regenerating this value and
// there is a stored value available then this function will return a hit.
if(!$item->isHit())
{
// Mark this instance as the one regenerating the cache. Because our
// protection method is Invalidation::OLD other Stash instances will
// use the old value and count it as a hit.
$item->lock();
// Run the relatively expensive code.
$userInfo = loadUserInfoFromDatabase($id);
// Store the expensive code so the next time it doesn't miss. The store
// function marks the stampede as over for now, so other Stash items
// will begin working as normal.
$pool->save($item->set($userInfo));
}
$userInfo
is the variable containing the array (or whatever), that Redis has stored. It is not necessarily an object, and it is certainly not an object that is usable as a Stash instance.
I think this is supposed to be $item
.
In a few places on the page about invalidation, it says that the invalidation method is set by passing additional values to "Item->get", such as:
There's also a mistake there, calling a method a class. In other instances, the method doesn't have parentheses at the end, such as here:
In the examples no additional values are passed to that method. Instead, a method not mentioned before is invoked, such as:
I still cannot understand how to control invalidation because of this. Also, you may want to replace things like "Item->get" with
ItemInterface#get()
, e.g. including proper inline code and displaying it as such.