Skip to main content
Drupal is a registered trademark of Dries Buytaert
Release: Views Bootstrap 5.5.4 — Minor update available for module views_bootstrap (5.5.4). Release: Rightup theme 1.0.3 — Minor update available for theme vartheme_bs5_rightup (1.0.3). Release: CommentOn 1.0.6 — Minor update available for module commenton (1.0.6). Release: ChatGPT Ads 1.0.3 — Minor update available for module chatgpt_ads (1.0.3). Release: Opensolr Search 5.1.3 — Minor update available for module opensolr_search (5.1.3). Release: ServiceM8 Webform Integration 1.2.1 — Minor update available for module servicem8_webform (1.2.1). Release: PostfixAdmin 1.0.0 — Initial release available for module postfix_admin (1.0.0)! Release: ip_analyser 1.0.3 — Minor update available for module ip_analyser (1.0.3). Module Revived: Swagger-PHP OpenAPI 3 documentation generator 1.0.0 — Module swagger_php updated after 10 months of inactivity (1.0.0). Security Coverage: Microsoft Azure AI — Module ai_provider_azure now has official Drupal security advisory coverage.

The module provides a service for storing and retrieving temporary data based on the user session.

This service can be used as like PrivateTempStore to make temporary, non-cache data available across requests. The data is stored in one key/value collection and expires automatically after a given timeframe.

The SessionBasedTempStore differs from the PrivateTempStore in that it doesn't create Drupal's cookie session, it means that you don't need to be afraid that Varnish will "MISS" the cache for the anonymous user because the cookie session does exist.

However, the issue with the PrivateTempStore was brought up here: #2743931
Unfortunately, it forcibly creates the cookie session for the anonymous user hence it interferes with a static cache like Varnish.

In contrast to PrivateTempStore, the SessionBasedTempStore creates a separate cookie with the unique ID of the owner storage so that it can subsequently interact with it to retrieve private data.

You may consider this module as a Drupal 8 generation of Session Cache API

This is an example of how you can use it:

/** @var \Drupal\session_based_temp_store\SessionBasedTempStoreFactory $temp_store_factory */
$temp_store_factory = \Drupal::service('session_based_temp_store');

/** @var \Drupal\session_based_temp_store\SessionBasedTempStore $temp_store */
$temp_store = $temp_store_factory->get('my_module_name', 4800); 
// As the second argument you can optionally set the exparaion time. If not set, by default it equals 604800 which is 7 days.
// As the third argument you can set the cookie path. The path on the server in which the cookie will be available on. By default, it's set to '/', it means the cookie will be available within the entire domain.


Here are the basic methods:

$temp_store->set('key', 'value');
$temp_store->get('key');
$temp_store->delete('key');


Additionally this service has following public methods:

// Retrieves an array of all values from the storage for the current collection and owner.
$temp_store->getAll();
// Deletes all data from the storage for the current collection and owner.
$temp_store->deleteAll();

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
2
Tracked since
Aug 2023
Latest release
2 years ago
Releases (12 mo)
0
Maintenance
Dormant

Releases

Version Type Core Release date
8.x-1.5 Stable Oct 12, 2023
8.x-1.4 Stable Aug 30, 2023