Skip to content

Commit

Permalink
Merge pull request #648 from joomlatools/feature/647-cache
Browse files Browse the repository at this point in the history
Improve cache location handling
  • Loading branch information
johanjanssens authored Apr 12, 2021
2 parents 4e63c14 + feda214 commit c080e5b
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 18 deletions.
27 changes: 18 additions & 9 deletions code/site/components/com_pages/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,14 @@
class ComPagesConfig extends KObject implements KObjectSingleton
{
protected $_site_path;
protected $_cache_path;

public function __construct(KObjectConfig $config)
{
parent::__construct($config);

$this->_site_path = $config->site_path;
$this->_site_path = $config->site_path;
$this->_cache_path = $config->cache_path;

//Load the site specific options
$this->_loadOptions();
Expand All @@ -24,23 +26,25 @@ public function __construct(KObjectConfig $config)
protected function _initialize(KObjectConfig $config)
{
$config->append(array(
'site_path' => Koowa::getInstance()->getRootPath().'/joomlatools-pages'
'site_path' => Koowa::getInstance()->getRootPath().'/joomlatools-pages',
))->append(array(
'cache_path' => $config->site_path.'/cache',
))->append(array(
'page_cache' => true,
'page_cache_path' => $config->site_path.'/cache/pages',
'page_cache_path' => $config->cache_path,
'page_cache_validation' => true,

'data_namespaces' => array(),
'data_cache' => true,
'data_cache_path' => $config->site_path ? $config->site_path.'/cache/data' : false,
'data_cache_path' => $config->cache_path ? $config->cache_path.'/data' : false,
'data_cache_validation' => true,

'template_cache' => true,
'template_cache_path' => $config->site_path ? $config->site_path.'/cache/templates' : false,
'template_cache_path' => $config->cache_path ? $config->cache_path.'/templates' : false,
'template_cache_validation' => true,

'http_cache' => false,
'http_cache_path' => $config->site_path ? $config->site_path.'/cache/responses': false,
'http_cache_path' => $config->cache_path ? $config->cache_path.'/pages': false,
'http_cache_time' => false,
'http_cache_time_browser' => null,
'http_cache_validation' => true,
Expand All @@ -50,9 +54,9 @@ protected function _initialize(KObjectConfig $config)
'http_static_cache' => getenv('PAGES_STATIC_ROOT') ? true : false,
'http_static_cache_path' => getenv('PAGES_STATIC_ROOT') ? getenv('PAGES_STATIC_ROOT') : false,

'http_resource_cache' => JFactory::getConfig()->get('caching'),
'http_resource_cache_path' => $config->site_path ? $config->site_path.'/cache/resources' : false,
'http_resource_cache_debug' => (JDEBUG ? true : false),
'http_client_cache' => JFactory::getConfig()->get('caching'),
'http_client_cache_path' => $config->cache_path ? $config->cache_path.'/responses' : false,
'http_client_cache_debug' => (JDEBUG ? true : false),

'collections' => array(),
'redirects' => array(),
Expand All @@ -77,6 +81,11 @@ public function getSitePath($path = null)
return $result;
}

public function getCachePath()
{
return $this->_cache_path;
}

public function get($option, $default = null)
{
return $this->getConfig()->get($option, $default);
Expand Down
2 changes: 1 addition & 1 deletion code/site/components/com_pages/data/registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ protected function _initialize(KObjectConfig $config)
$config->append([
'http' => 'com://site/pages.http.cache',
'cache' => $this->getObject('pages.config')->debug ? false : true,
'cache_path' => $this->getObject('pages.config')->getSitePath('cache'),
'cache_path' => $this->getObject('pages.config')->getCachePath(),
'cache_validation' => true,
'namespaces' => array(),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function _initialize(KObjectConfig $config)
$config->append(array(
'priority' => self::PRIORITY_LOWEST,
'cache' => false,
'cache_path' => $this->getObject('pages.config')->getSitePath('cache'),
'cache_path' => $this->getObject('pages.config')->getCachePath(),
'cache_time' => false, //static
'cache_time_shared' => false, //static
));
Expand Down
4 changes: 2 additions & 2 deletions code/site/components/com_pages/http/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ protected function _initialize(KObjectConfig $config)
{
$config->append([
'cache' => false,
'cache_path' => $this->getObject('pages.config')->getSitePath('cache'),
'cache_path' => $this->getObject('pages.config')->getCachePath(),
'debug' => $this->getConfig('pages.config')->debug ? true : false,

]);
Expand Down Expand Up @@ -105,7 +105,7 @@ public function send(KHttpRequestInterface $request)
public function locateCache($url)
{
$key = crc32((string)$url);
$file = $this->getConfig()->cache_path.'/resource_'.$key.'.php';
$file = $this->getConfig()->cache_path.'/response_'.$key.'.php';

return $file;
}
Expand Down
2 changes: 1 addition & 1 deletion code/site/components/com_pages/model/cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function _initialize(KObjectConfig $config)
{
$config->append([
'type' => 'cache',
'cache_path' => $this->getObject('pages.config')->getSitePath('cache'),
'cache_path' => $this->getObject('pages.config')->getCachePath(),
'identity_key' => 'id',
]);

Expand Down
2 changes: 1 addition & 1 deletion code/site/components/com_pages/page/registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function _initialize(KObjectConfig $config)
{
$config->append([
'cache' => $this->getConfig('pages.config')->debug ? false : true,
'cache_path' => $this->getObject('pages.config')->getSitePath('cache'),
'cache_path' => $this->getObject('pages.config')->getCachePath(),
'cache_validation' => true,
'collections' => array('pages' => ['model' => 'com://site/pages.model.pages']),
'redirects' => array(),
Expand Down
6 changes: 3 additions & 3 deletions code/site/components/com_pages/resources/config/site.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@

],
'com://site/pages.http.cache' => [
'cache' => $config['http_resource_cache'],
'cache_path' => $config['http_resource_cache_path'],
'debug' => $config['http_resource_cache_debug'],
'cache' => $config['http_client_cache'],
'cache_path' => $config['http_client_cache_path'],
'debug' => $config['http_client_cache_debug'],
],
'com://site/pages.model.cache' => [
'cache_path' => $config['http_cache_path'],
Expand Down

0 comments on commit c080e5b

Please sign in to comment.