Daily laravel-20160629| Redistaggedcache

Source: Internet
Author: User

<?phpnamespace Illuminate\Cache;// a namespace Cacheclass RedisTaggedCache  extends taggedcache{// a cache class about the cache use in  Redistagged    /**     * forever reference key.      *     *  @var  string      */    const REFERENCE_KEY_FOREVER =  ' FOREVER ';// too long  time to set the key values    /**      * standard reference key.     *     *   @var  string     */    const reference_key_ standard =  ' Standard ';// standard reference key.    /**      * store an item in the cache.     *      *  @param   string   $key      *  @param   mixed     $value      *  @param   \datetime|int  $ minutes     *  @return  void     */     public function put ($key,  $value,  $minutes  = null)      {         $this->pushstandardkeys ($this->tags-> GetNamespace (),  $key)         parent::p ut ($key,  $value,   $minutes);// key values time[minutes]    }// store a  item into the redis cache.    /**     *  Store an item in the cache indefinitely.     *     *  @param   string   $key      *  @param   mixed     $value      *  @return  void     */     public function forever ($key,  $value)     {          $this->pushforeverkeys ($this->tags->getnamespace (),  $key);         parent::forever ($key,  $value);    }//  store an item in the cache in the cache indefinitely    // use a parents function to set a long time ,so  wo can wrapper is as forever    /**      * remove all items from the cache.     *     * @ Return void     */    public function flush ()     {         $this->deleteforeverkeys ();          $this->deletestandardkeys ();         parent::flush ();     }// flush is a remove, remove  all item from the cache.    /**     *  Store standard key references into store.     *      *  @param   string   $namespace      *   @param   string   $key      *  @return  void      */     protected function pushstandardkeys ($namespace,  $key)      {         $this->pushkeys ($namespace,  $key,  self:: Reference_key_standard);     }//store standard key references into  store.    /**     * Store forever key  references into store.     *     *  @param   string   $namespace      *  @param   string    $key      *  @return  void     */     protected function pushforeverkeys ($namespace,  $key)     {          $this->pushkeys ($namespace,  $key,  self::reference_key_ FOREVER);    }// store forever key references into store.    /**      * store a reference to the cache key against  the reference key.     *     *  @param   string   $namespace      *  @param   string    $key      *  @param   string   $reference       *  @return  void     */    protected  function pushkeys ($namespace,  $key,  $reference)     {          $fullKey  =  $this->getprefix (). SHA1 ($namespace). ': ' $key;//  set real key        foreach  (Explode (' | '),  $ namespace)  as  $segment) &nbsP {             $this->store->connection () Lpush ($this->referencekey ($segment,  $reference),  $fullKey);         }// explode the string to array    }// store  a reference to the cache key against the reference key.     /**     * delete all of the items  that were stored forever.     * delete all of  the items that were stored forever.     *  @return  void     */    protected function  Deleteforeverkeys ()     {         $this Deletekeysbyreference (Self::reference_key_foreveR);     }// delete key that be forever    /**      * delete all standard items.     *      *  @return  void     */     Protected function deletestandardkeys ()     {          $this->deletekeysbyreference (self::reference_key_standard);    }//  Delete all standard items.    /**     * find  and delete all of the items that were stored against a  reference.     *     *  @param   string    $reference      *  @return  void     */    &nBsp;protected function deletekeysbyreference ($reference)     {         foreach  (Explode (' | ',  $this->tags->getnamespace ())  as  $segment)  {             $this->deletevalues ($segment  =  $this->referencekey ($segment,  $reference);              $this->store->connection ()->del ($segment);         }    }// find and delete all of  the items that were stored against a reference.   //  this we  find a way,the like to do some thing,    // first set a cell function,then call it ' s.     /**      * delete item keys that have been stored against a  reference.     *     *  @param   string    $referenceKey      *  @return  void     * /    protected function deletevalues ($referenceKey)     {          $values  = array_unique ($this->store-> Connection ()->lrange ($referenceKey,  0, -1));         if   (COUNT ($values)  > 0)  {             call_user_func_array ([$this->store->connection (),  ' del '],  $values);         }    }// delete item keys that  have been stored against a reference.   //    /**     *  get the reference key for the segment.     *      *  @param   string   $segment       *  @param   string   $suffix      *  @return   String     */    protected function referencekey ($ segment,  $suffix)     {        return $ This->getprefix (). $segment. ': '. $suffix;    }// get the reference  Key for the segment.}


This article is from the "Focus on PHP" blog, please be sure to keep this source http://lijinghsan.blog.51cto.com/3357095/1760310

Daily laravel-20160629| Redistaggedcache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.