Giter VIP home page Giter VIP logo

cache's Introduction

Kohana PHP Framework

Kohana is an elegant, open source, and object oriented HMVC framework built using PHP5, by a team of volunteers. It aims to be swift, secure, and small.

Released under a BSD license, Kohana can be used legally for any open source, commercial, or personal project.

Documentation

Kohana's documentation can be found at http://kohanaframework.org/documentation which also contains an API browser.

The userguide module included in all Kohana releases also allows you to view the documentation locally. Once the userguide module is enabled in the bootstrap, it is accessible from your site via /index.php/guide (or just /guide if you are rewriting your URLs).

Reporting bugs

If you've stumbled across a bug, please help us out by reporting the bug you have found. Simply log in or register and submit a new issue, leaving as much information about the bug as possible, e.g.

  • Steps to reproduce
  • Expected result
  • Actual result

This will help us to fix the bug as quickly as possible, and if you'd like to fix it yourself feel free to fork us on GitHub and submit a pull request!

cache's People

Contributors

acoulton avatar bluehawk avatar brmatt avatar cbandy avatar darkspider avatar enmand avatar enov avatar kiall avatar neo22s avatar paulchubatyy avatar rafis avatar samsoir avatar shadowhand avatar zeelot avatar zombor 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

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

cache's Issues

Default cache behavior inconsistent

The docs are a little unclear on cache behavior and the code has a potential to cause confusing behavior

From comment in Cache.php#L52

In cases where only one cache group is required, if the group is named default there is no need to pass the group name when instantiating a cache instance. (To me at least this reads as Cache::instance() == Cache::instance("default") )

From user guide

 $cache = Cache::instance();

The default group will use whatever is set to [Cache::$default] and must have a corresponding configuration definition for that group

The code actually supports the 2nd statement, I'd suggest either removing or clarifying the first block or setting Cache::$default in Cache.php to "default" instead of "file" especially since the config ship's commented out you are not leaving anything in a broken state.

failed to open stream: No such file or directory

on line 470 I get so many RuntimeException (s) there should be a check around it if file exists or not before it?

RuntimeException [ 0 ]: SplFileInfo::openFile(.../cache/3a/3ae1f572b12efae209db8e0db92985eb10c66631.cache): failed to open stream: No such file or directory
MODPATH/cache/classes/Kohana/Cache/File.php [ 470 ]
465 */
466 protected function _is_expired(SplFileInfo $file)
467 {
468 // Open the file and parse data
469 $created = $file->getMTime();
470 $data = $file->openFile("r");
471 $lifetime = (int) $data->fgets();
472
473 // If we're at the EOF at this point, corrupted!
474 if ($data->eof())
475 {
MODPATH/cache/classes/Kohana/Cache/File.php [ 470 ] » SplFileInfo->openFile(arguments)
0
string(1) "r"
465 */
466 protected function _is_expired(SplFileInfo $file)
467 {
468 // Open the file and parse data
469 $created = $file->getMTime();
470 $data = $file->openFile("r");
471 $lifetime = (int) $data->fgets();
472
473 // If we're at the EOF at this point, corrupted!
474 if ($data->eof())
475 {
MODPATH/cache/classes/Kohana/Cache/File.php [ 144 ] » Kohana_Cache_File->_is_expired(arguments)
0
object SplFileInfo(0) {
}
139 return $default;
140 }
141 else
142 {
143 // Test the expiry
144 if ($this->_is_expired($file))
145 {
146 // Delete the file
147 $this->_delete_file($file, FALSE, TRUE);
148 return $default;
149 }
MODPATH/redback/classes/Cache/File.php [ 15 ] » Kohana_Cache_File->get(arguments)
0
string(13) "widget_170_en"
1
NULL
10 if (Kohana::$profiling === TRUE and class_exists('Profiler', FALSE)) {
11 // Start a new benchmark
12 $benchmark = Profiler::start('Cache get', FUNCTION . ' ' . $id);
13 }
14 if (Kohana::$caching) {
15 $return = parent::get($id, $default);
16 }
17 if (isset($benchmark)) {
18 // Stop the benchmark
19 Profiler::stop($benchmark);
20 }

Memcache max key size

Seems the Key can not be longer than 250 characters.

So if you are caching DB queries as I do you will have many issues ;)

I can modify it here https://github.com/kohana/cache/blob/3.3/master/classes/Kohana/Cache.php#L298

So its global to anyone, or I can do it directly on memcache driver.

I honestly think the best would be to do a sha1 of the key if its more than 250 chars.

Something like:

    protected function _sanitize_id($id)
    {
        if (strlen($id)>250)
            return sha1($id);
        else
            return str_replace(array('/', '\\', ' '), '_', $id);
    }

testes in file , apc and memcache and working.

What do you think?

performance degradation on big memcache instances

Hello.
We're using quite big memcached instance for our application - 4GB (8 threads, large pages enabled), which, apparently, causes whole application to significantly slow down. I see gradual rise of Load Average from 2-5 to 20-30 when we pass 512MB cache size mark. If we purge the cache, LA drops back to normal within a couple of minutes.
Things got a little bit better after we switched from TCP socket to UNIX socket. And right now we've limited this memcached instance to 512M and it looks like LA did rise a bit after cache usage passed 256M mark, but it's insignificant.
get/set rates are around 400/160-175 req/s, but this shouldn't be too much - this is memcached after all.

Where should we start looking into this issue?

We use Kohana 3.3.2 running on Debian 7 with PHP 5.4.36 and memcache 1.4.13 (via memcache driver).

Why no default driver?

Most modules have a default basic working configuration set. For this module, that could be the file cache (given that the directory it uses is used by Kohana core). Is there a reason that there's no default driver?

Thanks!

Cache TTL may produce unexpected behaviour, and has a flickering test

As observed in kohana/kohana#41, it seems like one of the inherited test in Kohana_Cache_FileTest may be flickering if the execution runs across two seconds.

The test case in CacheBasicMethodsTest appears to specify that:

  • When ->set is called with a value and TTL 0
  • And the test does not wait between set and get
  • Then ->get should return the cached value

The File driver code checks if a value has expired with the following test:

if (($created + (int) $lifetime) < time())

This usually passes the test, because the < means the value doesn't expire till the end of the second it was set in - but if the test happens to start late in a second so that the get falls into the next second it will fail.

Obviously we need to make the test cope with second boundaries, but I think there's a bigger issue in that I would expect a TTL of 0 to mean "this expires immediately" / "don't cache this at all".

My hunch is that many of the native drivers would fail this test every time. Currently most of their tests are skipped on travis, and APC's TTL support is broken in CLI but I think it would probably also fail in a browser. I need to do a bit more investigation to see if I'm right.

If so, I think this is a bug in 3.3 and we should change the test so that:

  • When ->set is called with a value and TTL 0
  • And the test does not wait between set and get
  • Then ->get should return the default value or NULL

And change the file driver so that it uses <= to check for expiry, so items expire at the beginning of the second when their lifetime is up, not the end.

Thoughts?

Bug in MemCache module

class Kohana_Cache_Memcache extends Cache implements Cache_Arithmetic {

line 216

public function set($id, $data, $lifetime = 3600)
{

    // If the lifetime is greater than the ceiling
    if ($lifetime > Cache_Memcache::CACHE_CEILING)
    {
        // Set the lifetime to maximum cache time
        $lifetime = Cache_Memcache::CACHE_CEILING + time();
    }
    // Else if the lifetime is greater than zero
    elseif ($lifetime > 0)
    {
        $lifetime += time();
    }
    // Else
    else
    {
        // Normalise the lifetime
        $lifetime = 0;
    }

    return $this->_memcache->set($this->_sanitize_id($id), $data, $this->_flags, $lifetime);
}

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

+time() not necessary this;
http://php.net/manual/ru/memcache.set.php

expire

Expiration time of the item. If it's equal to zero, the item will never
expire. You can also use Unix timestamp or a number of seconds starting from
current time, but in the latter case the number of seconds may not exceed
2592000 (30 days).

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.