Daily laravel-20160630| Repository-1

Source: Internet
Author: User

Namespace illuminate\cache;use closure;use datetime;use arrayaccess;use carbon\carbon ; use badmethodcallexception;use illuminate\contracts\cache\store;use illuminate\support\traits\ macroable;use illuminate\contracts\events\dispatcher;use illuminate\contracts\cache\repository  as cachecontract;// a namespace be used enoughclass repository  implements cachecontract, arrayaccess{// two interface that should be  implements by repository    use macroable {         __call as macrocall;    }// use macroable  that we will be a __call    /**      * the cache store implementation.     * the cache  store     *  @var  \Illuminate\Contracts\Cache\Store     */     protected  $store;// a cache store instance of the  Implementation    /**     * the event dispatcher  implementation.     *     *  @var  \illuminate \contracts\events\dispatcher     */    protected  $events;//  The event dispatcher implementation a events interface     /**     * The default number of minutes to  store items.     *     *  @var  int      */    protected  $default  = 60; // a normal  time[minutes]or[seconds] to set the value into the store items .   //  normal set it is 60 second    /**      * create a new cache repository instance.     *      *  @param   \Illuminate\Contracts\Cache\Store   $store      *  @return  void     */     Public function __construct (store  $store)     {          $this->store =  $store;     }// a big __ set to create a new instance about cache, repository     a library to store.    /**     * set  the event dispatcher instance.     *     *  @param    \illuminate\contracts\events\dispatcher   $events      *  @return   Void     */    public function seteventdispatcher ( dispatcher  $events)     {         $this events =  $events;    }// set the event dispatcher  instance.   // a big set to the events.    /* *     * fire an event for this cache instance.      *     *  @param   string   $event      *  @param   array   $payload       *  @return  void      */   // fire an event for this cache  instance.    protected function firecacheevent ($event,  $payload)//  fire cache event    {        if   (! isset ($this->events))  {             return;        }// check this is a  normal events        switch  ($event)  {//  This->events is a instance about a class, then the events  is a way or a type             case  ' hit ':// case hit:                 if  (COUNT ($payload)  == 2)  {                      $payload [] = [];                 }                 return  $this->events->fire (new  Events\cachehit ($payload [0],  $payload [1],  $payload [2]);             case  ' missed ':// case missed:                 if  (Count ($payload)  == 1)  {                       $payload [] = [];                 }                return $ This->events->fire (new events\cachemissed ($payload [0],  $payload [1]);             case  ' Delete ':// case delete:                 if  (Count ($payload)  ==  1)  {                      $payload [] = [];                 }                 return  $this->events->fire (New events\keyforgotten ($payload [0],   $payload [1]);            case  ' write ' :// cache write:                if  ( Count ($payload)  == 3)  {                      $payload [] = [];                 }                 return  $this->events->fire (new events\ Keywritten ($payload [0],  $payload [1],  $payload [2],  $payload [3]);         }    }// a switch way to change the  Result    /**     * determine if an item  exists in the cache.     *     * @ Param  string   $key      *  @return  bool     */     public function has ($key)     {         return ! is_null ($this->get ($key));     }// determine[ check] the item has exists in the cache.    /**      * retrieve an item from the cache by key.  Retrieve an item from the cache by key.      *     *  @param   string   $key      *   @param   mixed    $default      *  @return  mixed      */    public function get ($key,  $default  = null)// GET&Nbsp;item by key.    {        if  (IS _array ($key))  {            return  $this- >many ($key);         }// the key is a array  ,will back a item array by many.          $value  =  $this->store->get ($this->itemkey ($key));// get item[value] by  key        if  (Is_null ($value))  {// null the  value             $this->firecacheevent (' Missed ',  [$key]);//missed             $value  = value ($default);        } else {              $this->firecacheevent (' hit ',  [$key,  $value]);//  Hit        }        return   $value;     }    /**     * retrieve  multiple items from the cache by key.// Retrieve multiple  Items from the cache     *     * items  not found in the cache will have a null value.// items  not found in the cache will have a null value      *     *  @param   array   $keys       *  @return  array     */    public  function many (Array  $keys)     {         $normalizedKeys   = [];        foreach  ($keys  as  $key  =>   $value)  {             $normalizedKeys []  = is_string ($key)  ?  $key  :  $value;         }         $values  =  $this->store->many ($ Normalizedkeys);        foreach  ($values  as  $key  = > & $value)  {            if  ( Is_null ($value))  {                  $this->firecacheevent (' missed ',  [$key]);                  $value  = isset ($keys [$key])  ? value ($keys [$key])  : null;             } else {                  $this->firecacheevent (' hit ',  [ $key,  $value]);            }         }        return  $values;     }


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

Daily laravel-20160630| Repository-1

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.