There are two caching mechanisms in RedBeanPHP, the Query Cache and the Bean Cache. I recommend to use the Query Cache, the Bean Cache is a plugin and it makes RedBeanPHP somewhat more complex to use.
In RedBeanPHP 3.4 you can use a very easy-to-use caching system: the Query Writer Cache. This caching mechanism will return the same result set for identical query-value pairs. The cache gets automatically flushed everytime something other than a select query is fired (i.e. an INSERT or DELETE). This means that this is a relatively safe cache to use. Issue the following statement to activate the Query Writer Cache:
R::useWriterCache(true); (3.5.1+)
//or...
R::$writer->setUseCache(true);
RedBeanPHP offers a Bean Cache. The bean cache can be configured like this:
$cachedOODB = new RedBean_Plugin_Cache($t->getWriter());
To allow the facade to use the cache (note that $t is a toolbox instance RedBean_ToolBox):
$t = R::$toolbox; //obtain old toolbox
R::configureFacadeWithToolbox(new RedBean_ToolBox(
$cachedOODB,
$t->getDatabaseAdapter(),
$t->getWriter()));
To flush cache:
$cache->flushAll();
You can also choose to flush cached beans of a given type:
$cache->flush($type);
RedBeanPHP Easy ORM for PHP © 2024 Gabor de Mooij and the RedBeanPHP community - Licensed New BSD/GPLv2