Drupal 8  8.0.2
SharedTempStore Class Reference

Public Member Functions

 __construct (KeyValueStoreExpirableInterface $storage, LockBackendInterface $lock_backend, $owner, RequestStack $request_stack, $expire=604800)
 
 get ($key)
 
 getIfOwner ($key)
 
 setIfNotExists ($key, $value)
 
 setIfOwner ($key, $value)
 
 set ($key, $value)
 
 getMetadata ($key)
 
 delete ($key)
 
 deleteIfOwner ($key)
 

Protected Attributes

 $storage
 
 $lockBackend
 
 $requestStack
 
 $owner
 
 $expire
 

Detailed Description

Stores and retrieves temporary data for a given owner.

A SharedTempStore can be used to make temporary, non-cache data available across requests. The data for the SharedTempStore is stored in one key/value collection. SharedTempStore data expires automatically after a given timeframe.

The SharedTempStore is different from a cache, because the data in it is not yet saved permanently and so it cannot be rebuilt. Typically, the SharedTempStore might be used to store work in progress that is later saved permanently elsewhere, e.g. autosave data, multistep forms, or in-progress changes to complex configuration that are not ready to be saved.

Each SharedTempStore belongs to a particular owner (e.g. a user, session, or process). Multiple owners may use the same key/value collection, and the owner is stored along with the key/value pair.

Every key is unique within the collection, so the SharedTempStore can check whether a particular key is already set by a different owner. This is useful for informing one owner that the data is already in use by another; for example, to let one user know that another user is in the process of editing certain data, or even to restrict other users from editing it at the same time. It is the responsibility of the implementation to decide when and whether one owner can use or update another owner's data.

If you want to be able to ensure that the data belongs to the current user, use .

Constructor & Destructor Documentation

__construct ( KeyValueStoreExpirableInterface  $storage,
LockBackendInterface  $lock_backend,
  $owner,
RequestStack  $request_stack,
  $expire = 604800 
)

Constructs a new object for accessing data from a key/value store.

Parameters
KeyValueStoreExpirableInterface$storageThe key/value storage object used for this data. Each storage object represents a particular collection of data and will contain any number of key/value pairs.
\Drupal\Core\Lock\LockBackendInterface$lock_backendThe lock object used for this data.
mixed$ownerThe owner key to store along with the data (e.g. a user or session ID).
\Symfony\Component\HttpFoundation\RequestStack$request_stackThe request stack.
int$expireThe time to live for items, in seconds.

References Drupal\requestStack().

Here is the call graph for this function:

Member Function Documentation

delete (   $key)

Deletes data from the store for a given key and releases the lock on it.

Parameters
string$keyThe key of the data to delete.
deleteIfOwner (   $key)

Deletes data from the store for a given key and releases the lock on it.

Only delete the given key if it is owned by $this->owner.

Parameters
string$keyThe key of the data to delete.
Returns
bool TRUE if the object was deleted or does not exist, FALSE if it exists but is not owned by $this->owner.
get (   $key)

Retrieves a value from this SharedTempStore for a given key.

Parameters
string$keyThe key of the data to retrieve.
Returns
mixed The data associated with the key, or NULL if the key does not exist.
getIfOwner (   $key)

Retrieves a value from this SharedTempStore for a given key.

Only returns the value if the value is owned by $this->owner.

Parameters
string$keyThe key of the data to retrieve.
Returns
mixed The data associated with the key, or NULL if the key does not exist.
getMetadata (   $key)

Returns the metadata associated with a particular key/value pair.

Parameters
string$keyThe key of the data to store.
Returns
mixed An object with the owner and updated time if the key has a value, or NULL otherwise.
set (   $key,
  $value 
)

Stores a particular key/value pair in this SharedTempStore.

Parameters
string$keyThe key of the data to store.
mixed$valueThe data to store.

References Drupal\requestStack().

Referenced by SharedTempStore\setIfOwner().

Here is the call graph for this function:

Here is the caller graph for this function:

setIfNotExists (   $key,
  $value 
)

Stores a particular key/value pair only if the key doesn't already exist.

Parameters
string$keyThe key of the data to check and store.
mixed$valueThe data to store.
Returns
bool TRUE if the data was set, or FALSE if it already existed.

References Drupal\requestStack().

Referenced by SharedTempStore\setIfOwner().

Here is the call graph for this function:

Here is the caller graph for this function:

setIfOwner (   $key,
  $value 
)

Stores a particular key/value pair in this SharedTempStore.

Only stores the given key/value pair if it does not exist yet or is owned by $this->owner.

Parameters
string$keyThe key of the data to store.
mixed$valueThe data to store.
Returns
bool TRUE if the data was set, or FALSE if it already exists and is not owned by $this->user.

References SharedTempStore\set(), and SharedTempStore\setIfNotExists().

Here is the call graph for this function:


The documentation for this class was generated from the following file: