Doctrine_Cache offers an intuitive and easy-to-use query caching solution. It provides the following things:

Doctrine_Cache hooks into Doctrine_Db eventlistener system allowing pluggable caching. It evaluates queries and puts SELECT statements in cache. The caching is based on propabalistics. For example if savePropability = 0.1 there is a 10% chance that a query gets cached.

Now eventually the cache would grow very big, hence Doctrine uses propabalistic cache cleaning. When calling Doctrine_Cache::clean() with cleanPropability = 0.25 there is a 25% chance of the clean operation being invoked. What the cleaning does is that it first reads all the queries in the stats file and sorts them by the number of times occurred. Then if the size is set to 100 it means the cleaning operation will leave 100 most issued queries in cache and delete all other cache entries.



Initializing a new cache instance:

addListener(\$cache); ?>"); ?>

Now you know how to set up the query cache. In the next chapter you'll learn how to tweak the cache in order to get maximum performance.