In the project, a reasonable use of caching is of great help to performance. Thinkphp provides a convenient way to cache, including data caching, static caching, and query caching, and support including file mode, APC, Db, Memcache, Shmop, Sqlite, Redis, Dynamic Data cache types, including eaccelerator and XCache, and 17813.html "> Customizable static caching rules, and provide a quick way to access operations."
Data caching
Cache operations in thinkphp, generally do not need to directly manipulate the cache class, because the system built-in cache operation is encapsulated, the 3.1 version of the recommended data caching method is the cache method, the basic use is:
1 Cache initialization
Cache (Array (' type ' => ' xcache ', ' expire ' =>60); parameters that can be supported by caching initialization vary according to the caching method, and the commonly used parameters are:
Expire cache expiration (time in seconds) prefix cache identifier prefix type cache type
Core version only http://www.aliyun.com/zixun/aggregation/19352.html ">file caching support, and other caching methods to support the need to download a separate cache driver, and put into the system directory extend/ driver/cache/below, error prompts that do not support cache types appear. Some caching methods have their own special parameters, such as memcache caching, and other parameters that need to be configured:
Cache (' type ' => ' memcache ', ' Host ' => ' 192.168.1.10 ', ' Port ' => ' 11211 ', ' prefix ' => ', ' ", ' expire ' = >60); For global caching, we generally recommend adding prefix (cache prefix) parameters to distinguish between different applications to avoid confusion.
2 Cache Settings
Cache (' A ', $value), caching data according to cached initialization parameters, or changing parameters when caching settings, such as cache (' A ', $value, 300);/cached data 300 seconds or even change previous cache mode or more parameters: Cache (' A ', $value, Array (' type ' => ' file ', ' expire ' =>300);/file caching of data 300 seconds if you use the array to pass the parameter in the cache setting, Can affect subsequent cache access.
3 Cache Reads
$value = Cache (' a '); caching reads the value of the previous cache setting, which is affected by the parameters passed in when the cache is initialized or when the cache is set.
Returns False if the cache identity does not exist or has expired, otherwise the cached value is returned.
4 Cache deletion
Deletes cached data that is identified as name by the cache.
If you want to switch caching, you can either cache initialization again or use the following method: If you set the cache prefix, the corresponding cache operation is only for the cache prefix should be identified, does not affect the other cache.
The data cache can support caching queues, simply by limiting the number of caches and specifying the length parameter when initializing:
Cache (' type ' => ' xcache ', ' length ' =>100, ' expire ' =>60); When the length parameter is set, the system caches only the last 100 cached data.