Module Description
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();

Project Usage
6731
Creation Date
Changed Date
Security Covered
Not Covered By Security Advisory
Version Available
Production
Module Summary
The module aims to solve the issue of creating a separate cookie session for storing and retrieving temporary data based on the user session, without interfering with Varnish cache for anonymous users.
Data Name
session_based_temp_store

OPENAI CHATBOT

OPENAI CHATBOT

15:48:25
Generic Chatbot
Hi, I'm a Drupal module expert powered by OpenAI, answering your questions about the Drupal module ecosystem. How can I be helpful today? Please note that we will log your question.