Yes, you can cache your data for your plugin, by creating a new
JCache instance and setting your custom options.
Something like below would do that:
// Reading global configuration params
$conf = JFactory::getConfig();
// Setting a location for your cached data.
$cacheBase = JPATH_SITE . '/cache/yourcachelocation';
// Your custom cachegroup
$cacheGroup = 'yourCacheGroup';
// Lifetime for your cache
$lifetime = 60;
// Setting your options
$options = array(
'defaultgroup' => $cacheGroup,
'storage' => $conf->get('cache_handler', ''),
'caching' => true,
'cachebase' => $cacheBase,
'lifetime' => $lifetime,
// Instantiate your cache object
$cache = JCache::getInstance('', $options);
// Create $cacheDataId
$cacheDataId = 'yourCacheDataId';
// It's time to check for cached data
if ($cache->get($cacheDataId) !== false )
$data = $cache->get($cacheDataId); // We got data from cache
// No cached data, fetch fresh data
$data = yourFreshDataGenerationMethod();
// Cache the data for the next time
// Do nice things with your $data
Update to include relevant info found in the comments:
You can use
$cachebase to select a custom location for your cached data.
Instead of specifying that you could use the
$cachegroup, which would do a similar thing.
What is most important is the
$cacheId when you are storing the data, as you will retrieve your stored cache data with this ID.
Note that if you give a custom directory path (
$cachebase) to store your cached data that does not exist, you will have to create that folder, otherwise it won't work, but using a Cache Group will auto-create the folders for your cache - (or at least this is how I remember it works...).
I recommend to experiment with these options and see exactly how they work.