PHP Класс MatthiasMullie\Scrapbook\Buffered\Utils\Transaction

This class accepts 2 caches: a KeyValueStore object (the real cache) and a Buffer instance (to read data from as long as it hasn't been committed) Every write action will first store the data in the Buffer instance, and then pas update along to $defer. Once commit() is called, $defer will execute all these updates against the real cache. All deferred writes that fail to apply will cause that cache key to be deleted, to ensure cache consistency. Until commit() is called, all data is read from the temporary Buffer instance.
Автор: Matthias Mullie ([email protected])
Наследование: implements MatthiasMullie\Scrapbook\KeyValueStore
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
$cache MatthiasMullie\Scrapbook\KeyValueStore
$defer Defer Deferred updates to be committed to real cache.
$local Buffer
$suspend boolean Suspend reads from real cache. This is used when a flush is issued but it has not yet been committed. In that case, we don't want to fall back to real cache values, because they're about to be flushed.
$tokens mixed[] We'll return stub CAS tokens in order to reliably replay the CAS actions to the real cache. This will hold a map of stub token => value, used to verify when we do the actual CAS.

Открытые методы

Метод Описание
__construct ( Buffer $local, MatthiasMullie\Scrapbook\KeyValueStore $cache )
add ( $key, $value, $expire )
cas ( $token, $key, $value, $expire ) Since our CAS is deferred, the CAS token we got from our original get() will likely not be valid by the time we want to store it to the real cache. Imagine this scenario: * a value is fetched from (real) cache * an new value key is CAS'ed (into temp cache - real CAS is deferred) * this key's value is fetched again (this time from temp cache) * and a new value is CAS'ed again (into temp cache.
commit ( ) : boolean Commits all deferred updates to real cache.
decrement ( $key, $offset = 1, $initial, $expire )
delete ( $key )
deleteMulti ( array $keys )
flush ( )
get ( $key, &$token = null )
getMulti ( array $keys, array &$tokens = null )
increment ( $key, $offset = 1, $initial, $expire )
replace ( $key, $value, $expire )
rollback ( ) : boolean Roll back all scheduled changes.
set ( $key, $value, $expire )
setMulti ( array $items, $expire )
touch ( $key, $expire )

Защищенные методы

Метод Описание
clear ( ) Clears all transaction-related data stored in memory.

Описание методов

__construct() публичный Метод

public __construct ( Buffer $local, MatthiasMullie\Scrapbook\KeyValueStore $cache )
$local Buffer
$cache MatthiasMullie\Scrapbook\KeyValueStore

add() публичный Метод

public add ( $key, $value, $expire )

cas() публичный Метод

..). In this scenario, when we finally want to replay the write actions onto the real cache, the first 3 actions would likely work fine. The last (second CAS) however would not, since it never got a real updated $token from the real cache. To work around this problem, all get() calls will return a unique CAS token and store the value-at-that-time associated with that token. All we have to do when we want to write the data to real cache is, right before was CAS for real, get the value & (real) cas token from storage & compare that value to the one we had stored. If that checks out, we can safely resume the CAS with the real token we just received. {@inheritdoc}
public cas ( $token, $key, $value, $expire )

clear() защищенный Метод

Clears all transaction-related data stored in memory.
protected clear ( )

commit() публичный Метод

that had already been written to will be deleted.
public commit ( ) : boolean
Результат boolean

decrement() публичный Метод

public decrement ( $key, $offset = 1, $initial, $expire )

delete() публичный Метод

public delete ( $key )

deleteMulti() публичный Метод

public deleteMulti ( array $keys )
$keys array

flush() публичный Метод

public flush ( )

get() публичный Метод

public get ( $key, &$token = null )

getMulti() публичный Метод

public getMulti ( array $keys, array &$tokens = null )
$keys array
$tokens array

increment() публичный Метод

public increment ( $key, $offset = 1, $initial, $expire )

replace() публичный Метод

public replace ( $key, $value, $expire )

rollback() публичный Метод

Roll back all scheduled changes.
public rollback ( ) : boolean
Результат boolean

set() публичный Метод

public set ( $key, $value, $expire )

setMulti() публичный Метод

public setMulti ( array $items, $expire )
$items array

touch() публичный Метод

public touch ( $key, $expire )

Описание свойств

$cache защищенное свойство

protected KeyValueStore,MatthiasMullie\Scrapbook $cache
Результат MatthiasMullie\Scrapbook\KeyValueStore

$defer защищенное свойство

Deferred updates to be committed to real cache.
protected Defer,MatthiasMullie\Scrapbook\Buffered\Utils $defer
Результат Defer

$local защищенное свойство

protected Buffer,MatthiasMullie\Scrapbook\Buffered\Utils $local
Результат Buffer

$suspend защищенное свойство

Suspend reads from real cache. This is used when a flush is issued but it has not yet been committed. In that case, we don't want to fall back to real cache values, because they're about to be flushed.
protected bool $suspend
Результат boolean

$tokens защищенное свойство

We'll return stub CAS tokens in order to reliably replay the CAS actions to the real cache. This will hold a map of stub token => value, used to verify when we do the actual CAS.
См. также: cas()
protected mixed[] $tokens
Результат mixed[]