Defer
    
            
            in package
            
        
    
    
    
This is a helper class for transactions. It will optimize the write going out and take care of rolling back.
Optimizations will be:
- multiple set() values (with the same expiration) will be applied in a single setMulti()
 - for a set() followed by another set() on the same key, only the latter one will be applied
 - same for an replace() followed by an increment(), or whatever operation happens on the same key: if we can pre-calculate the end result, we'll only execute 1 operation with the end result
 - operations before a flush() will not be executed, they'll just be lost
 
Rollback strategy includes:
- fetching the original value of operations prone to fail (add, replace & cas) prior to executing them
 - executing said operations before the others, to minimize changes of interfering concurrent writes
 - if the commit fails, said original values will be restored in case the new value had already been stored
 
This class must never receive invalid data. E.g. a "replace" can never follow a "delete" of the same key. This should be guaranteed by whatever uses this class: there is no point in re-implementing these checks here. The only acceptable conflicts are when cache values have changed outside, from another process. Those will be handled by this class.
Tags
Table of Contents
Methods
- __construct() : mixed
 - __destruct() : mixed
 - add() : void
 - cas() : void
 - clear() : void
 - Clears all scheduled writes.
 - commit() : bool
 - Commit all deferred writes to cache.
 - decrement() : void
 - delete() : void
 - deleteMulti() : void
 - flush() : void
 - increment() : void
 - replace() : void
 - set() : void
 - setMulti() : void
 - touch() : void
 
Methods
__construct()
    public
                    __construct(KeyValueStore $cache) : mixed
    Parameters
- $cache : KeyValueStore
 
__destruct()
    public
                    __destruct() : mixed
    Tags
add()
    public
                    add(string $key, mixed $value, int $expire) : void
    Parameters
- $key : string
 - $value : mixed
 - $expire : int
 
cas()
    public
                    cas(mixed $originalValue, string $key, mixed $value, int $expire) : void
    Parameters
- $originalValue : mixed
 - 
                    
No real CAS token, but the original value for this key
 - $key : string
 - $value : mixed
 - $expire : int
 
clear()
Clears all scheduled writes.
    public
                    clear() : void
    commit()
Commit all deferred writes to cache.
    public
                    commit() : bool
    When the commit fails, no changes in this transaction will be applied (and those that had already been applied will be undone). False will be returned in that case.
Return values
booldecrement()
    public
                    decrement(string $key, int $offset, int $initial, int $expire) : void
    Parameters
- $key : string
 - $offset : int
 - $initial : int
 - $expire : int
 
delete()
    public
                    delete(string $key) : void
    Parameters
- $key : string
 
deleteMulti()
    public
                    deleteMulti(array<string|int, string> $keys) : void
    Parameters
- $keys : array<string|int, string>
 
flush()
    public
                    flush() : void
    increment()
    public
                    increment(string $key, int $offset, int $initial, int $expire) : void
    Parameters
- $key : string
 - $offset : int
 - $initial : int
 - $expire : int
 
replace()
    public
                    replace(string $key, mixed $value, int $expire) : void
    Parameters
- $key : string
 - $value : mixed
 - $expire : int
 
set()
    public
                    set(string $key, mixed $value, int $expire) : void
    Parameters
- $key : string
 - $value : mixed
 - $expire : int
 
setMulti()
    public
                    setMulti(array<string|int, mixed> $items, int $expire) : void
    Parameters
- $items : array<string|int, mixed>
 - $expire : int
 
touch()
    public
                    touch(string $key, int $expire) : void
    Parameters
- $key : string
 - $expire : int