Here I will answer the File based cache
with the code. Which is not exactly the HTML
cache, but performs well.
Look at my Laravel Installation /var/www/ea (This is my Laravel Installation directory)
Step 1: How to create cache
Step 2: This step comes before step 1, which is configure
cache to file
cache. Open the config/cache.php
and do check two things
'default' => env('CACHE_DRIVER', 'file'),
//It means your cache default driver is File based.
Then
'path' => storage_path('framework/cache'),
//This is the path My screenshot is showing above.
Step 3: Lets write the code to create cache.
Open your Controller method and write following
\Cache::put( 'cachekey', 'Hello I am Abdul', 1 ); // 1- minute
laravel documentation for cache
Step 4: Check for any new directory created inside framework/cache/
That's your cache file.
// Following code check if the cache key already exists before creating,
// otherwise create cache file
if (Cache::has('key')){
Cache::get('key');
} else {
Cache::put('key', $values, 10);
}