doulu3808 2016-12-18 10:31
浏览 405
已采纳

如何将Laravel视图转换为静态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.

  1. How can i get views to be served as static HTML with route caching enabled?
  2. How can i serve the static HTML views from the users cache using HTTP headers?
  3. Are there any other caveats or performance boosting tricks i can/should utilise?
  • 写回答

1条回答 默认 最新

  • duanfei9278 2017-01-03 13:39
    关注

    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)

    Inside storage/framework/cache you will find the cached files

    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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊