SharedTempStore

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 \Drupal\user\PrivateTempStore.

Hierarchy

File

core/modules/user/src/SharedTempStore.php, line 38

Namespace

Drupal\user

Members

Name Modifiers Type Description
SharedTempStore::$expire protected property The time to live for items in seconds.
SharedTempStore::$lockBackend protected property The lock object used for this data.
SharedTempStore::$owner protected property The owner key to store along with the data (e.g. a user or session ID).
SharedTempStore::$requestStack protected property The request stack.
SharedTempStore::$storage protected property The key/value storage object used for this data.
SharedTempStore::delete public function Deletes data from the store for a given key and releases the lock on it.
SharedTempStore::deleteIfOwner public function Deletes data from the store for a given key and releases the lock on it.
SharedTempStore::get public function Retrieves a value from this SharedTempStore for a given key.
SharedTempStore::getIfOwner public function Retrieves a value from this SharedTempStore for a given key.
SharedTempStore::getMetadata public function Returns the metadata associated with a particular key/value pair.
SharedTempStore::set public function Stores a particular key/value pair in this SharedTempStore.
SharedTempStore::setIfNotExists public function Stores a particular key/value pair only if the key doesn't already exist.
SharedTempStore::setIfOwner public function Stores a particular key/value pair in this SharedTempStore.
SharedTempStore::__construct public function Constructs a new object for accessing data from a key/value store.
doc_Drupal
2016-10-29 09:42:16
Comments
Leave a Comment

Please login to continue.