简体   繁体   中英

Doctrine Memcached: Clear cache after save record

Does Doctrine 1.* clearing cache after save record?

It seems like it doesn't. Can I do it somewhere?

No it doesn't. You should clear your cache manually each time you saved an object.

As describe in the doc , the best way is to do it using event, specially, postSave event:

// lib/model/doctrine/User.class.php

class User extends BaseUser
{
  // ...

  public function postSave($event)
  {
    $cacheDriver = $this->getTable()->getAttribute(Doctrine_Core::ATTR_RESULT_CACHE);
    $cacheDriver->deleteByPrefix('users_');
  }
}

You can also built a custom class to manage the cache clear ( as describe here ):

<?php
class myCache{

    public static function clearRegexMatches($regex){
       Doctrine_Manager::getInstance()
            ->getAttribute(Doctrine_Core::ATTR_RESULT_CACHE)
            ->deleteByRegex($regex);
    }

    public static function clearOne($name){
        Doctrine_Manager::getInstance()
            ->getAttribute(Doctrine_Core::ATTR_RESULT_CACHE)
            ->delete($name);
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM