This article mainly introduces the THINKPHP5 framework cache query operation, combined with the instance form analysis of thinkPHP5 cache settings, use, query and other related operation skills, the need for friends can refer to the following
This example describes the THINKPHP5 framework cache query operation. Share to everyone for your reference, as follows:
Cache Settings and use:
1. Set the following in \application\config.php:
' Cache ' = = [ //using composite cache type ' type ' = ' complex ', //default cache ' = ' = ' =/ /Drive mode ' Type ' = = ' File ', //!! In this setting the substitution cache mode //Cache Save Directory ' path ' = Cache_path, ], //File cache ' files ' = [ / /drive Mode ' type ' = ' file ', //Set different cache to save directory ' path ' = Runtime_path. ' file/', ], //Redis cache ' Redis ' = [ //Drive mode ' type ' = ' Redis ', // Server address ' host ' = ' 127.0.0.1 ', ],],
2, the Controller
Use \think\cache;
3. Use in the controller
Cache::set (' name ', ' Tom ', 3600); Cache::get (' name ');
Cache query:
1. Simple Cache query:
In any controller (if you want to complete the data query in model, you need to use the DB Class)
Public Function Cacheselect () { $_data = db (' table name ')->cache ()->find (); Dump ($_data); 60s internal cache to extract data, no need to query from the database}
2, set the specified cache identity, make the query more efficient, more convenient to use:
Public Function Cacheselect () { $result = db (' table name ')->cache (' Random character ')->where (' id ', ' < ', ten)->select ();} The CacheKey method is any method of the arbitrary controller Public Function CacheKey () { //In other places directly invoke the found data, avoid querying again: $data = \think\cache::get (' Random characters '); Dump ($data);}
The above is the whole content of this article, I hope that everyone's learning has helped, more relevant content please pay attention to topic.alibabacloud.com!