ThinkPHP3.1.3 core class Cache. class. php

Source: Internet
Author: User
ThinkPHPlibcoreCache. class. php I. Sample Code note three functions 1. Connect to the cache publicfunctionconnect ($ type, $ optionsarray () {if (empty ($ type )) $ typeC (DATA_CACHE_TYPE); $ typestrtolower (trim ($ type); $ classCache. ucwords ($ type)

/ThinkPHP/lib/core/Cache. class. php I. Sample Code note three functions 1. connect to the cache public function connect ($ type =, $ options = array () {if (empty ($ type )) $ type = C (DATA_CACHE_TYPE); $ type = strtolower (trim ($ type); $ class = Cache. ucwords ($ type)

/ThinkPHP/lib/core/Cache. class. php

I. Sample Code

Three functions are worth noting.

1. Connection Cache

Public function connect ($ type = '', $ options = array () {if (empty ($ type) $ type = C ('data _ CACHE_TYPE '); $ type = strtolower (trim ($ type); $ class = 'cache '. ucwords ($ type);/* call different Cache Engines Based on Different types. By default, TP only provides file caching methods in Lib/Driver/Cache/CacheFile. class. php */if (class_exists ($ class) $ cache = new $ class ($ options); else throw_exception (L ('_ CACHE_TYPE_INVALID _'). ':'. $ type); return $ cache ;}

2. Obtain cache instances

static function getInstance() {       $param = func_get_args();        return get_instance_of(__CLASS__,'connect',$param);    }
The get_instance_of function in function. php is called here. In fact, the singleton mode is independent.


3. Queue Cache

Set the cache length.

If cache queue is not enabled, as long as the set cache is continuously added during the time-out period

If the cache length is set to 10, the first cache of the queue is deleted when the number of caches exceeds 10 according to the "first-in-first-out" principle of the queue.


Ii. Small programming details:

1,

public function __get($name) {        return $this->get($name);    }    public function __set($name,$value) {        return $this->set($name,$value);    }
This shows the idea of object-oriented polymorphism.

Subclass inherits the Cache class. $ this-> set () in the Cache class is the method in the subclass of the call.

2. get_instance_of function in function. php

Standalone mode is a good method.



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.