/** * Reads from the vB Optimise cache
*
* @param string Referencing the vB Optimise option varname
* @param string The cache key to read from
*/
public static function read($cacheType, $key)
{
if (!self::_canCache($cacheType))
{
// We can't cache this
return -1;
}
// Fetch the vBO data
$_data = vb_optimise::$cache->get('dbtech.thanks.' . $key);
if (is_array($_data) AND TIMENOW < $_data['time'])
{
// We saved some queries
vb_optimise::stat(1);
vb_optimise::report('Fetched dbtech.thanks.' . $key . ' from cache successfully.');
return $_data['cache'];
}
return false;
}
/**
* Writes to the vB Optimise cache
*
* @param string Database table we are working with
* @param string (Optional) Any additional clauses to the query
*/
public static function write($data, $cacheType, $key)
{
if (!self::_canCache($cacheType))
{
// We can't cache this
return false;
}
// By default, we want to "null out" the cache
$_data = false;
if ($data !== false)
{
// Write the vBO data
$_data = array(
'time' => TIMENOW + (self::$vbulletin->options['vbo_cache_thanks' . $cacheType] * 3600),
'cache' => $data,
);
}
// Write the cache
vb_optimise::$cache->set('dbtech.thanks.' . $key, $_data);
vb_optimise::report('Cached dbtech.thanks.' . $key . ' successfully.');
return true;
}
/**
* Writes to the vB Optimise cache
*/
public static function flush()
{
if (!self::_canCache())
{
// We can't cache this
return false;
}
// Flush the cache
vb_optimise::$cache->flush();
return true;
}
/**
* Tests whether we can cache something
*
* @param string Original message
* @param string Overriding
*/
protected static function _canCache($cacheType = '')
{
if (!class_exists('vb_optimise'))
{
// We don't have vBO installed
return false;
}
if (!isset(self::$vbulletin->options['vbo_online']))
{
// vBO is turned off
return false;
}
if (!is_object(vb_optimise::$cache))
{
// Not a valid cache object
return false;
}
if (!$cacheType)
{
// This will be used for the flush
return true;
}
if (!isset(self::$vbulletin->options['vbo_cache_thanks' . $cacheType]))
{
// vBO's version is too old
return false;
}
if (!self::$vbulletin->options['vbo_cache_thanks' . $cacheType])
{
// The cache time has been turned off
return false;
}
return true;
}
Here's a couple functions from the APTL mod that may help:
We use essential cookies to make this site work, and optional cookies to enhance your experience.