Hmm, I think it's best to back up and talk about the role of a cache vs. the role of a registry.
In PHP, a cache is used to store objects, text, and other stuff that might have been complex, timely, resource intensive or otherwise expensive to generate. It is stored in a fashion such that the cost of generating whatever it was is not incurred on each and every request, but so that the cost is incurred on one request, and the result can be shared across multiple requests. (Remember, PHP is a shared-nothing architecture, objects cannot be shared between requests without some form of serializing-storing-unserializing). That is what Zend_Cache is for.
Zend_Registry, on the other hand, serves a much different purpose. Following the mantra "globals are evil", Zend_Regstry allows for a static place that objects can be stored so that they can be retrieved from a known place during the lifetime of a request. A typical scenario might be this: a bootstrap script creates a database object, or even a cacheManager object, then inside a controller script you need to retrieve those objects. Since the objects are inside of the application's registry, you know that is the place where they can be retrieved from. Zend_Registry does not persist objects between requests; meaning any contents will be destroyed at request end, and will need to be re-created on the next request to be used. Zend_Registry is more for code convenience, not performance.
Hope that helps,
Ralph
没有评论:
发表评论