Drupal 8  8.0.2
PrivateTempStore Class Reference

Public Member Functions

 __construct (KeyValueStoreExpirableInterface $storage, LockBackendInterface $lock_backend, AccountProxyInterface $current_user, RequestStack $request_stack, $expire=604800)
 
 get ($key)
 
 set ($key, $value)
 
 getMetadata ($key)
 
 delete ($key)
 

Protected Member Functions

 createkey ($key)
 
 getOwner ()
 

Protected Attributes

 $storage
 
 $lockBackend
 
 $currentUser
 
 $requestStack
 
 $expire
 

Detailed Description

Stores and retrieves temporary data for a given owner.

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

The PrivateTempStore is different from a cache, because the data in it is not yet saved permanently and so it cannot be rebuilt. Typically, the PrivateTempStore 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.

The PrivateTempStore differs from the SharedTempStore in that all keys are ensured to be unique for a particular user and users can never share data. If you want to be able to share data between users or use it for locking, use .

Constructor & Destructor Documentation

__construct ( KeyValueStoreExpirableInterface  $storage,
LockBackendInterface  $lock_backend,
AccountProxyInterface  $current_user,
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).
int$expireThe time to live for items, in seconds.

References Drupal\currentUser(), and Drupal\requestStack().

Here is the call graph for this function:

Member Function Documentation

createkey (   $key)
protected

Ensures that the key is unique for a user.

Parameters
string$keyThe key.
Returns
string The unique key for the user.

References PrivateTempStore\getOwner().

Referenced by PrivateTempStore\delete(), PrivateTempStore\get(), PrivateTempStore\getMetadata(), and PrivateTempStore\set().

Here is the call graph for this function:

Here is the caller graph for this function:

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.
Returns
bool TRUE if the object was deleted or does not exist, FALSE if it exists but is not owned by $this->owner.

References PrivateTempStore\createkey().

Here is the call graph for this function:

get (   $key)

Retrieves a value from this PrivateTempStore 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.

References PrivateTempStore\createkey().

Here is the call graph for this function:

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.

References PrivateTempStore\createkey().

Here is the call graph for this function:

getOwner ( )
protected

Gets the current owner based on the current user or the session ID.

Returns
string The owner.

References Drupal\currentUser(), and Drupal\requestStack().

Referenced by PrivateTempStore\createkey(), and PrivateTempStore\set().

Here is the call graph for this function:

Here is the caller graph for this function:

set (   $key,
  $value 
)

Stores a particular key/value pair in this PrivateTempStore.

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

References PrivateTempStore\createkey(), PrivateTempStore\getOwner(), and Drupal\requestStack().

Here is the call graph for this function:


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