TIP: Use Markdown or, <pre> for multi line code blocks / <code> for inline code.
These forums are read-only and for archival purposes only!
Please join our new forums at discourse.kohanaframework.org
Caching queries
  • How can I cache queries, orm queries, etc... using apc/eacc? Is there any way to do it without doing much work?

  • First thing I would recommend is caching table discovery queries (SHOW INDEX). You can also try looking here but as it says it is not tested: https://gist.github.com/kemo/2513471

  • To cache SHOW INDEX queries, overwrite list_columns() function the ORM

  • I didn't ask proper question, I don't want to cache models, I want to cache database results using apc/eacc without chaning implementation, like this : $query->cached($time)->execute() or $orm_model->....->cached($time)->find();

  • but this one use Kohana::cache() based on file system not apc or eacc

  • $query->cached($time) uses kohana::cache() and I want to use apc or eacc instead of file system

  • @averate change method - replace file cache on apc - where problem?

  • I don't want to change core/modules, I would like to have portable code

  • @averatec I guess what @WinterSilence suggests, is adding a line like this:

    Cache::$default ='apc';

    or, in case you supply an enviromental variable through your web server (the way I do it):

    Cache::$default = (Kohana::$environment === Kohana::PRODUCTION) ? 'apc' : 'file';

    to your bootstrap.php

  • I don't think so, because Kohana::cache() uses file system even ur default instance is different

  • @averatec, @WinterSilence is right. Kohana's Cache is already portable. There are enough implemented drivers to chose from.

    @vev, that's cool! Switchin' drivers easier than flippin' burgers.

  • http://kohanaframework.org/3.3/guide-api/Database_Query_Builder#execute check this... any query will be cached with Kohana::cache that uses file system even you set any other default cache instance -.- and I want to change this without changing original files of database module and system files

  • Hmmm.... It seems you're right, too.

    He's right, and he's right - they can't both be right

  • then anybody knows answer?

  • @averatec, would this help you? untested:

    class Kohana extends Kohana_Core
        public static function cache($name, $data = NULL, $lifetime = NULL) {
            // Check if official cache is enabled in modules ?? array_key_exists('cache', Kohana::modules()) ??
            if (class_exists('Kohana_Cache')) {
                if ($data === NULL) {
                    return Cache::instance()->get($name);
                } else {
                    return Cache::instance()->set($name, $data, $lifetime);
            } else {
                return parent::cache($name, $data, $lifetime);


  • awesome love you man :D I think it works, but will test it later

  • i understand:
    me: @averate change method - replace file cache on apc - where problem?
    averate: I don't want to change core/modules, I would like to have portable code

    but @enov example its what i said

  • Now I understand you @WinterSilence. Anyway thanks guys fo help : )

  • No need check cache module - override suggests this
    Not all use Kohana_Cache module
    If you check module also need check apc library:

    if (function_exists('apc_store') AND ini_get('apc.enabled'))
        Cache::$default = 'apc';

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion