| Current Path : /proc/1908984/root/proc/1908984/root/home/digilove/www/41423/ |
| Current File : //proc/1908984/root/proc/1908984/root/home/digilove/www/41423/Cache.php.tar |
home/digilove/public_html/libraries/regularlabs/src/Cache.php 0000644 00000004513 15234634577 0020405 0 ustar 00 <?php
/**
* @package Regular Labs Library
* @version 23.7.24631
*
* @author Peter van Westen <info@regularlabs.com>
* @link https://regularlabs.com
* @copyright Copyright © 2023 Regular Labs All Rights Reserved
* @license GNU General Public License version 2 or later
*/
namespace RegularLabs\Library;
defined('_JEXEC') or die;
use Joomla\CMS\Factory as JFactory;
/**
* Class Cache
* @package RegularLabs\Library
* @deprecated Use CacheNew
*/
class Cache
{
static $cache = [];
static $group = 'regularlabs';
// Is the cached object in the cache memory?
public static function get($id)
{
$hash = md5($id);
if ( ! isset(self::$cache[$hash]))
{
return false;
}
return is_object(self::$cache[$hash]) ? clone self::$cache[$hash] : self::$cache[$hash];
}
// Get the cached object from the cache memory
public static function has($id)
{
return isset(self::$cache[md5($id)]);
}
// Save the cached object to the cache memory
public static function read($id)
{
if (JFactory::getApplication()->get('debug'))
{
return false;
}
$hash = md5($id);
if (isset(self::$cache[$hash]))
{
return self::$cache[$hash];
}
$cache = JFactory::getCache(self::$group, 'output');
return $cache->get($hash);
}
// Get the cached object from the Joomla cache
public static function set($id, $data)
{
self::$cache[md5($id)] = $data;
return $data;
}
// Save the cached object to the Joomla cache
public static function write($id, $data, $time_to_life_in_minutes = 0, $force_caching = true)
{
if (JFactory::getApplication()->get('debug'))
{
return $data;
}
$hash = md5($id);
self::$cache[$hash] = $data;
$cache = JFactory::getCache(self::$group, 'output');
if ($time_to_life_in_minutes)
{
// convert ttl to minutes
$cache->setLifeTime($time_to_life_in_minutes * 60);
}
if ($force_caching)
{
$cache->setCaching(true);
}
$cache->store($data, $hash);
self::set($hash, $data);
return $data;
}
}
home/digilove/public_html/plugins/system/nrframework/NRFramework/Cache.php 0000644 00000005275 15242067523 0023072 0 ustar 00 <?php
/**
* @author Tassos Marinos <info@tassos.gr>
* @link https://www.tassos.gr
* @copyright Copyright © 2024 Tassos All Rights Reserved
* @license GNU GPLv3 <http://www.gnu.org/licenses/gpl.html> or later
*/
/**
* This file is deprecated. Use CacheManager instead of Cache.
*/
namespace NRFramework;
defined('_JEXEC') or die;
use \NRFramework\CacheManager;
use \Joomla\CMS\Factory;
/**
* Caching mechanism
*/
class Cache
{
/**
* Check if has alrady exists in memory
*
* @param string $hash The hash string
*
* @return boolean
*/
static public function has($hash)
{
$cache = CacheManager::getInstance(Factory::getCache('tassos', ''));
return $cache->has($hash);
}
/**
* Returns hash value
*
* @param string $hash The hash string
* @param string $clone Why the hell we clone objects here?
*
* @return mixed False on error, Object on success
*/
static public function get($hash, $clone = true)
{
$cache = CacheManager::getInstance(Factory::getCache('tassos', ''));
return $cache->get($hash, $clone);
}
/**
* Sets on memory the hash value
*
* @param string $hash The hash string
* @param mixed $data Can be string or object
*
* @return mixed
*/
static public function set($hash, $data)
{
$cache = CacheManager::getInstance(Factory::getCache('tassos', ''));
return $cache->set($hash, $data);
}
/**
* Reads hash value from memory or file
*
* @param string $hash The hash string
* @param boolean $force If true, the filesystem will be used as well on the /cache/ folder
*
* @return mixed The hash object valuw
*/
static public function read($hash, $force = false)
{
$cache = CacheManager::getInstance(Factory::getCache('tassos', ''));
return $cache->read($hash, $force);
}
/**
* Writes hash value in cache folder
*
* @param string $hash The hash string
* @param mixed $data Can be string or object
* @param integer $ttl Expiration duration in milliseconds
*
* @return mixed The hash object value
*/
static public function write($hash, $data, $ttl = 0)
{
$cache = CacheManager::getInstance(Factory::getCache('tassos', ''));
return $cache->write($hash, $data, $ttl);
}
/**
* Memoize a function to run once per runtime
*
* @param string $key The key to store the result of the callback
* @param callback $callback The callable anonymous function to call
*
* @return mixed
*/
static public function memo($key, callable $callback)
{
$hash = md5($key);
if (Cache::has($hash))
{
return Cache::get($hash);
}
return Cache::set($hash, $callback());
}
}