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

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图