GithubHelp home page GithubHelp logo

kohana-cache's People

Contributors

paulchubatyy avatar samsoir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

airpos

kohana-cache's Issues

There is a possibility for race condition in `file.php`

        // If file does not exist
        if ( ! $file->isFile())
        {
            // Return default value
            return $default;
        }
        else
        {
            // Open the file and extract the json
            $json = $file->openFile()->current();

            // Decode the json into PHP object
            $data = json_decode($json);

            // Test the expiry
            if ($data->expiry < time())
            {
                // Delete the file
                $this->_delete_file($file, NULL, TRUE);

                // Return default value
                return $default;
            }
            else
            {
                return ($data->type === 'string') ? $data->payload : unserialize($data->payload);
            }
        }

There is a chance to read the file contents while another thread is writing to a file.

I've caught that just once for 2 years, and this is how the exception looked like:

 Kohana_Cache_Exception [ 0 ]: Kohana_Cache_File::get failed to unserialize cached object with message : Trying to get property of non-object ~ MODPATH/cache/classes/kohana/cache/file.php [ 170 ]

So I think that the file was written only partially and $json contained malformed json, what leaded to a NULL in $data.

Proposed solution - add if (!$data) return $default; after decoding

Config 'default_expire' doesn't work with memcache

$lifetime is always set to 0 if not provided in the set() method when using the memcached driver. By changing $lifetime = 0 to $lifetime = Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE); in classes/kohana/cache/memcache.php:103 the problem is solved.

missing constant on cache.php

I think, this constant is missing on cache.php

const DEFAULT_EXPIRE = 3600;

too many cache driver use this constant, sample:

Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE)

Declaration of Kohana_Cache_Sqlite::set() should be compatible with that of Kohana_Cache::set()

I use kohana 3.0.4.

Declaration of Kohana_Cache_Sqlite::set() should be compatible with that of Kohana_Cache::set()

MODPATH/cache-samsoir\classes\kohana\cache\sqlite.php [ 13 ]

 8  * @category   Cache
 9  * @author     Kohana Team
10  * @copyright  (c) 2009-2010 Kohana Team
11  * @license    http://kohanaphp.com/license
12  */
13 class Kohana_Cache_Sqlite extends Cache implements Kohana_Cache_Tagging {
14 
15  /**
16   * Database resource
17   *
18   * @var  PDO

Typo in memcache.php

Line 209:

$liftime = Cache_Memcache::CACHE_CEILING + time();

Should be:

$lifetime = Cache_Memcache::CACHE_CEILING + time();

missing APPPATH on default config

default config and file config is have missing APPPATH.

 'cache_dir' => 'cache/.kohana_cache',

to

 'cache_dir' => 'APPPATH.cache/kohana_cache',

some missing lines on file.php

I compare with sqlite driver and find some missing lines and small errors on file driver.


    protected function __construct(array $config)
    {
        parent::__construct($config); // missing, I added
    
        try
        {
            //$directory = Arr::get($config, 'cache_dir', APPPATH.Cache_File::CACHE_DIR); // wrong, I comment
            $directory = Arr::get($this->_config, 'cache_dir', APPPATH.Cache_File::CACHE_DIR); // true, I added
            $this->_cache_dir = new RecursiveDirectoryIterator($directory);
        }

File cache unexpected behavior

Hello!
Your plugin is amazing, but there are several problems with file cache.

1)public function set($id, $data, $lifetime = NULL)

lifetime is not used in code, and that would be good..
maybe i missed something, but setting lifetime doesn`t work

2)public function get($id, $default = NULL)

expiration check looks strange
if ($file->getMTime() < (time() - Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE)))

as i understand it approves problem#1

3)problem with serialize/unserialize functions in php directly.. it doesn`t work well with strings that contains \r and \n.. maybe use base64 or json instead?

UnexpectedValueException

File cache driver:

/**
 * Constructs the file cache driver
 *
 * @param array config
 * @throws Kohana_Cache_Exception
 */
protected function __construct(array $config)
{
parent::__construct($config);

try
{
$directory = Arr::get($this->_config, 'cache_dir', APPPATH.Cache_File::CACHE_DIR);
$this->_cache_dir = new RecursiveDirectoryIterator($directory);
}
// You are catching wrong exception here. At least php 5.3 reports so.
catch (ErrorException $e)
{
if ( ! mkdir($directory, 0777, TRUE))
{
throw new Kohana_Cache_Exception('Failed to create the defined cache directory : :directory', array(':directory' => $directory));
}
chmod($directory, 0777);
$this->_cache_dir = new RecursiveDirectoryIterator($directory);
}

Details: http://www.php.net/~helly/php/ext/spl/classUnexpectedValueException.html

$_config property with sqlite driver in config defaults

Changing default driver to sqlite in config file returned me an error in using cache library.

Cache::$instances[$group] passes driver name in $group param, not Kohana_Config configuration. So __construct($config) don't gets needed Kohana_Config, but an array of cache default group.
To initialize $_config property in right way in __construct() method I made this:

protected function __construct($config)
{
    $_config = Kohana::config('cache');
    $this->_config = $_config->get($config['driver']);
}

Abstract the drivers

I think it would be useful to simply type Cache::instance() instead of knowing which caching class to use specifically

I feel like it would be something that might have to be switched around as traffic builds on your site

maybe allow for specifying which driver to use with a parameter to instance() (default to a config item)... I'm not sure if an app would ever need to use 2 different caching systems

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.