?
Related to # 6796
Referenced as Pull Request for: # 6796
avatar ollyja
ollyja
17 Nov 2013

Steps to reproduce the issue

  1. set cachetime to 5 in configuration.php
  2. clear out any caches under cache directory
  3. run below sample code:
    test1.php
    <?php 
       function getUsers($query) {
          $db = JFactory::getDbo();
          $db->setQuery($query);
          return $db->loadObjectList();
       }
       function getCachedUsers() {
          $cache = JFactory::getCache('com_test');
          $query = "SELECT * FROM #__users limit 5";
          $data = $cache->get("getUsers", $query, "testlimit_id");
          print_r($data);
       }
       getCachedUsers();
    ?>
    test2.php: 
    <?php 
       function getUsers($query) {
          $db = JFactory::getDbo();
          $db->setQuery($query);
          return $db->loadObjectList();
       }
       function getCachedUsers() {
          $cache = JFactory::getCache('com_test');
          $query = "SELECT * FROM #__users limit 5";
          $data = $cache->get("getUsers", $query, "testlimit_id");
          print_r($data);
       }
       function getCachedUsers2() {
          $cache = JFactory::getCache('com_test');
          $query = "SELECT * FROM #__users WHERE id>10";
          $data = $cache->get("getUsers", $query, "testrange_id");
          print_r($data);
       }
       getCachedUsers2();
       sleep(6);
       getCachedUsers();
    ?>
    

Expected result

Run script:
$> php test1.php; sleep 1; php test2.php

The cache for testlimit_id should be valid in test2.php, since we set cachetime to 5 minutes

Actual result

The cache is actually regenerated in test2.php at the end. The cache file modification time is checked from ls --full-time output

System information (as much as possible)

Linux; Joomla 3.2 latest.

Additional comments

It seems this line causes the problem:
in joomla/cache/cache.php, function store():
$handler->_lifetime = $this->_options['lifetime'];

The _lifetime is expected in seconds, but $this->_options['lifetime'] is actually in minutes

avatar ollyja ollyja - open - 17 Nov 2013
avatar brianteeman brianteeman - change - 28 Jul 2014
The description was changed
Title
cache stroage llifetime was reset to wrong value
cache storage llifetime was reset to wrong value
Build .
avatar brianteeman brianteeman - change - 2 Sep 2014
Category Cache
avatar atpatil11
atpatil11 - comment - 18 Oct 2014

@ollyja How your trying it. I checked with Joomla core, third party extension as well. Its working. Are you trying to execute the script using Command Line? Using Joomla CLI?

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2539.

avatar ollyja
ollyja - comment - 20 Oct 2014

@atpatil11, yes, this was tested from Joomla CLI and was testing the file-based caching. As far as I remember, this issue was found when I tried to perform cache gc.

This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2539.

avatar brianteeman brianteeman - change - 23 Nov 2014
Category Cache Cache CLI
avatar brianteeman brianteeman - change - 3 Jan 2015
Labels Added: ?
avatar roland-d
roland-d - comment - 14 Mar 2015

@ollyja I am aware it has been a while since you posted this issue. I am looking into reproducing this but I can't seem to reproduce the problem. Could you give some more detailed code which you used that triggered this issue?

Thanks.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2539.
avatar ollyja
ollyja - comment - 14 Mar 2015

@roland-d How did you test it ? I have moved away from file based caching to memcached, but as far as I checked last time in Joomla latest release, the issue seemed to be still there.

If you intend to run above scripts, make sure to put them into joomla cli folder, copy some library import code from cli/garbagecron.php, then I think you should see the issue. Please let me know what other information you need from me, and thanks to follow up on this.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2539.
avatar roland-d
roland-d - comment - 15 Mar 2015

@ollyja I managed to get the CLI scripts to run, I guess I had been staring at it for too long yesterday ;) So I modified the test scripts to use only 1 ID, the testlimit_id and see how that went.

The time limit I have set to 3 minutes, once this limit has passed a new cache file is written, so to me that is working as expected.

The second file created by the test script provided above is correct because it has a different ID, which in turn creates a new cache file as each cache is unique based on the set of options.

So I would say this is no longer an issue in 3.4.0. In the code I see the timelimit is also 900 seconds for a 15-minute cache.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2539.
avatar ollyja
ollyja - comment - 16 Mar 2015

@roland-d After seeing your comment, I did a quick try on latest 3.4.0 release, but it seemed to me the problem is still there. Here are my testing code:

cli/test1.php

 

/**
 * @package    Joomla.Cli
 *
 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

// Initialize Joomla framework
const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
    require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', dirname(__DIR__));
    require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

JFactory::getConfig(JPATH_BASE."/configuration.php"); 

function getUsers($query) {
   $db = JFactory::getDbo();
   $db->setQuery($query);
   return $db->loadObjectList();
}
function getCachedUsers() {
   $cache = JFactory::getCache('com_test');
   $query = "SELECT * FROM #__users limit 5";
   $data = $cache->get("getUsers", $query, "testlimit_id");
   print_r($data);
}

getCachedUsers();

cli/test2.php:

 

/**
 * @package    Joomla.Cli
 *
 * @copyright  Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
 * @license    GNU General Public License version 2 or later; see LICENSE.txt
 */

// Initialize Joomla framework
const _JEXEC = 1;

// Load system defines
if (file_exists(dirname(__DIR__) . '/defines.php'))
{
    require_once dirname(__DIR__) . '/defines.php';
}

if (!defined('_JDEFINES'))
{
    define('JPATH_BASE', dirname(__DIR__));
    require_once JPATH_BASE . '/includes/defines.php';
}

// Get the framework.
require_once JPATH_LIBRARIES . '/import.legacy.php';

// Bootstrap the CMS libraries.
require_once JPATH_LIBRARIES . '/cms.php';

JFactory::getConfig(JPATH_BASE . "/configuration.php"); 

function getUsers($query) {
   $db = JFactory::getDbo();
   $db->setQuery($query);
   return $db->loadObjectList();
}
function getCachedUsers() {
   $cache = JFactory::getCache('com_test');
   $query = "SELECT * FROM #__users limit 5";
   $data = $cache->get("getUsers", $query, "testlimit_id");
   print_r($data);
}
function getCachedUsers2() {
   $cache = JFactory::getCache('com_test');
   $query = "SELECT * FROM #__users WHERE id>10";
   $data = $cache->get("getUsers", $query, "testrange_id");
   print_r($data);
}

getCachedUsers2(); 
sleep(6);
getCachedUsers();

configuration.php (most are same as installation/configuration.php-dist):

class JConfig {
        ... 
    /* Database Settings */
    public $dbtype = 'mysqli';               // Normally mysqli
    public $host = 'localhost';              // This is normally set to localhost
**  public $user = 'testuser';                       // DB username**
**  public $password = 'password';                   // DB password**
**  public $db = 'testdb';                         // DB database name**
    public $dbprefix = 'jos_';               // Do not change unless you need to!
        ...  

    /* Cache Settings */
**  public $caching = '1';**
**  public $cachetime = '2';**
    public $cache_handler = 'file';
        ...
}

Test Result:

run scripts from cli folder: 
$> php test1.php; ls -al --full-time ../cache/com_test/; sleep 2; php test2.php; ls -al --full-time ../cache/com_test/

1. after running test1.php, the cache file is: 
  $> ls -al --full-time ../cache/com_test/
-rw-rw-r-- 1 olly olly 1635 2015-03-15 22:21:33.617474100 -0400 97f10f3853728535494f0bfa8c2702dd-cache-com_test-6ab76d843e7ecfda29171a181cbcd76a.php


2. after running test2.php, the cache files are: 
  $> ls -al --full-time ../cache/com_test/
-rw-rw-r-- 1 olly olly 1133 2015-03-15 22:21:36.667456180 -0400 97f10f3853728535494f0bfa8c2702dd-cache-com_test-1dae96b7085d29f3baf394af96a0ab3a.php
-rw-rw-r-- 1 olly olly 1635 2015-03-15 22:21:42.669420914 -0400 97f10f3853728535494f0bfa8c2702dd-cache-com_test-6ab76d843e7ecfda29171a181cbcd76a.php

As you can see, the 97f10f3853728535494f0bfa8c2702dd-cache-com_test-6ab76d843e7ecfda29171a181cbcd76a.php cache file has newer timestamp after running test2.php, which means the cache file was just modified. This should not happen as our cachetime is 2 minutes.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2539.
avatar roland-d roland-d - change - 18 Apr 2015
Status New Confirmed
Rel_Number 6796
Relation Type Related to
avatar roland-d
roland-d - comment - 18 Apr 2015

@ollyja Thank you for your eloborate feedback. I was now able to reproduce the issue and your suggested fix works for me as well. I have created a pull request and that is linked to this ticket. Once the pull request gets 2 successful tests we can move ahead and get it merged into the core. Thank you for your contribution.


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/2539.

avatar zero-24
zero-24 - comment - 29 Apr 2015

Closing here as we have a pull request here: #6796 Thanks :smile:

avatar zero-24 zero-24 - change - 29 Apr 2015
Status Confirmed Closed
Closed_Date 0000-00-00 00:00:00 2015-04-29 21:51:28
Closed_By zero-24
Labels Removed: ?
avatar zero-24 zero-24 - close - 29 Apr 2015

Add a Comment

Login with GitHub to post a comment