我想设置功能,将Laravel 5.3中的视图转换为静态HTML,并将其提供给访客,直到CMS调用指定。 我还想使用HTTP标头来缓存访问者计算机上的页面。
如何在启用了路由缓存的情况下将视图作为静态HTML提供? 如何使用HTTP标头从用户缓存中提供静态HTML视图? 是否可以/应该使用其他任何警告或性能提升技巧?I would like to setup functionality to transform the views in Laravel 5.3 to static HTML and serve it to visitors untill specified from a CMS call. I also like to use HTTP headers to cache the pages on a visitors computer.
How can i get views to be served as static HTML with route caching enabled? How can i serve the static HTML views from the users cache using HTTP headers? Are there any other caveats or performance boosting tricks i can/should utilise?最满意答案
在这里,我将使用代码回答File based cache 。 这不完全是HTML缓存,但表现良好。
看看我的Laravel Installation / var / www / ea(这是我的laravel Instalaltion目录)
Step 1:如何创建缓存
Step 2:此步骤在Step 2:之前,即configure缓存到file缓存。 打开config/cache.php并检查两件事
'default' => env('CACHE_DRIVER', 'file'), //这意味着您的缓存默认驱动程序是基于文件的。
然后'path' => storage_path('framework/cache'), //这是我的屏幕截图在上面显示的路径。
第3步:让我们编写代码来创建缓存。 打开Controller方法并编写以下内容
\Cache::put( 'cachekey', 'Hello I am Abdul', 1 ); // 1分钟
缓存的laravel文档
第4步:检查在framework/cache/创建的任何新目录
那是你的缓存文件。
//在创建之前检查缓存键是否已经存在,否则创建缓存文件if (Cache::has('key')){ Cache::get('key'); } else { Cache::put('key', $values, 10); } if (Cache::has('key')){ Cache::get('key'); } else { Cache::put('key', $values, 10); }
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- minutelaravel 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); }更多推荐
HTML,HTTP,视图,views,缓存,电脑培训,计算机培训,IT培训"/> <meta name="descrip
发布评论