dqol6556 2013-12-16 12:45
浏览 52
已采纳

使用Framework(特别是Laravel 4.1)根据'Region'进行缓存

I am currently revamping our current website which runs on Drupal 6, and I have suggested to move it over to a custom CMS, which I will write using Laravel 4.1.

Most of it I have planned out, one of the major issues which I cannot seem to get my head around is regional caching.

Background of the Regions

We have different content for different regions, and what we are doing in the current site is appending a GET variable to the URL : example.tld/pageName/?region=123

This is fine, except the issue is caching, and our current caching system is terrible, it's slow and pointless even using it (driven from the database for a start). I want to cache the output to the disk, which means I can use something like memcached or similar (or even the built-in Laravel caching methods).

What we're caching

Currently we are caching regional specific content on certain pages. For example:

Page 123 Region A

will have different content to

Page 123 Region B

And we cache the content depending on the region

So I have two main questions:

  1. What is the best way to store/retrieve the region ID for a specified user?
  2. What is the best way to store/retrieve the associated data for that page/view for the specified region ID?

Thanks!

  • 写回答

1条回答 默认 最新

  • duan205571 2013-12-16 17:35
    关注
    1. I would recommend storing the region ID in your database and then capturing that into their session when they login (assuming you have a login system). If you don't have a login for the user, use whatever method you are currently using to capture their region.
    2. As someone else recommended, I'd suggest using composite keys. I'm using redis for this now. Cache::put('Region:A:123', $data).

    If you store their region in the user's session, you could capture that directly in your controller to have to "automagically" load the correct region data. For example,

    Login page

    Session::put('region', 'A');
    

    Controller where you need to capture region specific data

    $cached = Cache::get('Region:' . Session::get('region') . ':123);
    

    Note there are a number of ways to perform caching on your site. Keep in mind that using Memcached/Redis means you're storing this data in main memory. So while it's going to be very fast, you may have less of it available. I bring that up because you mention in your post "cache to disk" and then mention memcached.

    Edited My Cache::put method call was incorrect.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置