1.Laravel provides a consistent API for a variety of cache systems, supported by file, memcached, and Redis 2. The Main method is put (), add (), Forever (), have (), get (), pull (), Forget ( ) 3. Configuration file path/config/cache.php 4. Add Route route::get ('/cache1 ', ' homecontroller@cache1 '); Route::get ('/cache2 ', ' homecontroller@cache2 '); 5. Add Cache Public Function Cache1 () {cache::p ut (' key1 ', ' val1 ', 10); Since we are using the default file cache here, after executing this method, a new cache file is generated under storage, as shown in the following figure
6. Other operations <?php namespace App\http\controllers; Use Illuminate\http\request; Use Illuminate\support\facades\cache;
Class HomeController extends Controller {public Function cache1 () {Cache::p ut (' key1 ', ' val1 ', 10);//Key value effective time (minutes)//cache:: Add (' Key2 ', ' val2 ', 20);//If Key2 does not exist, add success otherwise, add failure//cache::forever (' Key3 ', ' val3 ');//Permanently save object to cache//cache::has (' Key1 '); /Determine if there is cache::forget (' key1 ');//Delete cache}
Public Function Cache2 () {///$data = Cache::get (' key1 ');//value $data = cache::p ull (' key1 ');//value after delete dd ($DATA)}}
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.