Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

yii delete all query cache

Tags:

php

memcached

yii

I am using Yii 1.14 on centos 5 with php 5.2.4. I am doing query caching like Projects::model()->cache(timeout,dependancy)->findAll(array()). Now I have many of these. is there a way to clear all the query cache of this application. i cannot seem to find any info of adding these cache queries to a group and then delete the group from the cache. The problem is i have many applications using memcache and i do not want to flush it every time before a update. I only want to clear all cache related to this application.

Updated I would like to flush the app cache on the beginning and end of update. i have no file beginning with cache in that location

 ll paradox/protected/runtime/
total 164
-rw-r--r-- 1 apache apache 155571 Jun  3 15:53 application.log
drwxr-xr-x 2 apache apache   4096 Jun  4 11:53 gii-1.1.12
drwxr-xr-x 2 apache apache   4096 Jun  4 11:53 gii-1.1.14

Looking at the logs the Yii::app()->cache->flush does following

<28 new auto-negotiating client connection
28: Client using the ascii protocol
<28 get ns9e5np1ss92i7mqkjues577o1
>28 sending key ns9e5np1ss92i7mqkjues577o1
>28 END
<39 version
>39 VERSION 1.4.5
<39 flush_all
>39 OK

That looks like it clears all the memcache?

like image 286
shorif2000 Avatar asked Mar 21 '26 09:03

shorif2000


1 Answers

To delete all cache data, use flush() method:

Yii::app()->cache->flush();

To delete all expired cache data, use gc() method:

Yii::app()->cache->gc();

Another way:

//if you use CFileCache
$cache=new CFileCache();
$cache->flush();
//if you use CMemCache
$cache2=new CMemCache();
$cache2->flush();

To find all related methods, take a look at the Yii Official document:

  • Caching
  • CFileCache
  • CMemCache
  • CApcCache

Note that, the flush method, only flushes current running app cache values.

like image 134
Ali MasudianPour Avatar answered Mar 22 '26 21:03

Ali MasudianPour



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!