Dynamic cache in Thinkphp (S method) and fast cache (F method), thinkphp_php tutorial

Source: Internet
Author: User

Dynamic cache in Thinkphp (S method) and fast cache (F method), thinkphp


The system is cached by default, and we can define other caching methods in the project configuration file, for example, modify the default cache mode to XCache (of course, your environment needs to support XCache)

For cache directories under file-mode caching, where there is a large number of file problems due to too much cache data, thinkphp also gives a solution to how the Hashits directory cache can be enabled.

' Data_cache_subdir ' =>true

You can also set the hierarchy of hash directories, such as

' Data_path_level ' =>2

You can automatically create multi-tier subdirectories to cache based on the hash of the cache identity.

The S method supports cache expiration, in many cases we may not need the concept of expiration, or the use of file-like caching to meet the requirements, so the system also provides a quick caching method specifically for file methods F method.The F method can only be used to cache simple data types and does not support expiration and cache objects, use the following:

Cache data quickly, saved by default in the Data_path directory
F (' data ', $data);
Cache data quickly and save to the specified directory
F (' Data ', $data, Temp_path);
F (' User/data ', $data);
Delete cached data
F (' data ', NULL);
Get Cached data
$data =f (' data ');

Configuration file config.php

Dynamic cache, cache file exists in \runtime\temp
' Data_cache_type ' = ' file ',
' Data_cache_time ' = ' 3600 ',
' Data_cache_subdir ' =>true,//open sub-directory
' Data_cache_level ' =>3,//sets the hierarchy of subdirectories

Action file:

Function view () {
Cache
$cache =cache::getinstance (' cache mode ', ' cache parameters ');
$cache =cache::getinstance (' Xcache ', Array (' expire ' =>60));
$cache->set (' name ', ' value '), or $cache->name= ' value ';
$value = $cache->get (' name '), or $value= $cache->name;
$cache->rm (' name '), or unset ($cache->name);

S (' name ', ' data ', ' 3600 ', ' type ') cache shortcut method

$user =m (' Haodetong ');

$value =s (' list ');
if (empty ($value)) {
$list = $user->select ();

S (' list ', $list, 3600);
Echo ' This is a file read directly from the database ';
Dump ($list);
}else{
Echo ' This is the cache file ';
Dump ($value);
}

}

The first visit is as follows:



Once again refreshed as:

http://www.bkjia.com/PHPjc/1064068.html www.bkjia.com true http://www.bkjia.com/PHPjc/1064068.html techarticle thinkphp in the dynamic cache (s method) and fast cache (F method), the thinkphp system is the default cache mode is the file cache, we can define it in the project configuration file ...

  • 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.