Hi Stefan,
> I'm in a similar situation. Just with much more Cache Files.
> Perhaps you can explain in more detail, what exactly you did :-)
Well, I have about 20 methods in several classes which basically include
an SQL selection. This data is serialized and cached. First, I used the
model class name and method name combined with the method parameters as
the cache id. Here are some cache id examples:
- Destination_Model_Main_fetchSuperiorDestinations_1
- Member_Model_Main_fetchMembersByDestination_1236_44_future
- Cms_Model_Menu_fetchContextMenu_de_destination_index_update
- Destination_Model_Main_fetchCountPerDestinationAndCategory_44
All data was cached with Zend_Cache_Backend_File in one directory (with
subdirectories).
Now I switched to Zend_Cache_Backend_Sqlite and for each method that
needs caching I use a separate sqlite database. Here is a code snippet:
class Travello_Cache
{
protected static $_instances = array();
public static function getInstance($method)
{
if (!isset(self::$_instances[$method])
|| null === self::$_instances[$method])
{
$config = Zend_Registry::get('config');
$cacheSqliteDb = $config['default']->cache->data_dir
. md5($method) . '.sqlite';
$frontendOptions = array(
'lifetime' => $config['default']->cache->data_lifetime,
'automatic_serialization' => true
);
$backendOptions = array(
'cache_db_complete_path' => $cacheSqliteDb,
'automatic_vacuum_factor' =>
$config['default']->cache->vacuum_factor,
);
self::$_instances[$method] = Zend_Cache::factory('Core',
'Sqlite', $frontendOptions, $backendOptions);
}
return self::$_instances[$method];
}
}
To use the instances of Zend_Cache I use it like this:
Travello_Cache::getInstance('Destination_Model_Main_fetchSuperiorDestinations')->clean();
Travello_Cache::getInstance('Member_Model_Main_fetchMembersByDestination')->save();
Travello_Cache::getInstance('Cms_Model_Menu_fetchContextMenu')->load();
I hope this helps a little to understand what I am currently doing.
Thanks and Best regards,
Ralf