Here are the examples for Magento 2:
Magento 2 Cookies
Magento 2 Registry
It allows using global variables in Magento (although web developers do not welcome global variables). Registry throws an exception when attempting to record data with already existing key. If the option is $graceful = false or just ignores re-record if $graceful = true.
SessionManagerInterface allows to record and read data in/from StorageInterface. Storage is a DataObject. Therefore, for sessions get/set accessors are used (via “magic” method_call):
In this example, we use the default namespace for data storage. Thus, there is a possibility of crossing the names of developers of other modules. To avoid this risk, we can add prefixes in variable names. It will help create unique names for methods like
Otherwise, you can use SessionManager’s implementations with a related SessionStorage with a different namespace.