CApcCache within a CApplicationComponent extension

Hi,

I have a CApplicationComponent extension which I am trying to use CApcCache on by calling:


Yii::app()->cache->addValue()

However it is giving this error:

CApcCache and its behaviors do not have a method or closure named "addValue".

Do I have to specifically include CApcCache for the component?

Thanks,

J

The best way is to include CApcCache instance in the extension as it is possible that Yii::app()->cache is not of CApcCache type.

In my main config file I have the line:


  'cache'=>array(

    'class'=>'system.caching.CApcCache'

  ),

and when calling cache the error states CApcCache…could the cache type still not be CApcCache?

Thanks,

J

Any got any idea about this one? - I dont want to include the cache function if it already being loaded somewhere else.

I have now included the CApcCache within my extension and instantiated it using




        // Init cache

        $this->cache = new CApcCache;

        $this->cache->init();


        $this->cache->addValue($this->searchRequestId,$this->constructCacheArray(),180);



However still getting the error:


CApcCache and its behaviors do not have a method or closure named "addValue"

any ideas?

Hi Guys,

I am really stuck with this one and need some help - has anyone got any suggestions?

  1. You should not add CApcCache to your extension.

  2. addValue is a protected method, you can not call it from outside. You should use set() instead. See CCache.

  3. You should not make your code dependend on a specific type of cache (in fact, that’s even hard to achieve as all cache components share the same interface)

  4. If your extension requires a cache component, you should note that in the documentation so that a developer can configure a cache component

Hi mike,

cheers, those all seem fair points. Have now got it working using:


Yii::app()->cache->set()

So should be independant to cache type.

Thanks,

J

You dont need all this

inside the component just use

Yii::app()->cache