Magento Registry – Understanding Magento Registry

registrysessionsingleton

I have been wondering always, where is all the registry data stored in Magento ?

I know that even singleton objects are stored in the registry. And registry is just a static array variable of the Mage class.

I have a couple of questions here to clear my confusion:

  1. Is registry different for different users ? I mean is it created on
    a per-user (per HTTP request) basis?

For example,

Mage::register('foo', 'Hello World'); //set a value for foo
Mage::registry('foo'); //will this return hello world for all HTTP users ?
  1. Is registry data stored in
    sessions ? If not how will Magento identify which user invoked the
    registry data ?

I have read Alan Storm's blog article as well as his answer on StackOverFlow regarding this. But I couldn't kill the confusion. Please correct me If I you think my basics are messed up. Thanks

Best Answer

The registry stores data to memory which is specific to that request (rather than user or anything else), and persists for the duration of that request only. The principle is very simple really, the Mage class is instantiated as a singleton object for every request and the instantiated Mage object remains in memory, and is accessible in all classes (and templates) until the request completes and the response is sent.

As the object is a singleton, whenever you access it you get the same object. All that is happening is that you are storing values to this object, so when one class stores a value, and another accesses it they are both working on the same object and the second class is able to retrieve the value the first class set.