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.