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?


图片转代码服务由CSDN问答提供 功能建议

我目前正在修改我们当前在Drupal 6上运行的网站,我建议将其移至自定义 CMS,我将使用Laravel 4.1编写。



我们针对不同地区有不同的内容,我们在当前网站上做的是附加一个 GET变量到URL:example.tld / pageName /?region = 123

这很好,除了问题是缓存,我们当前的缓存系统很糟糕,它甚至很慢而且毫无意义 使用它(从数据库驱动开始)。 我想将输出缓存到磁盘,这意味着我可以使用像 memcached 或类似的东西(甚至是内置的Laravel缓存方法)。


目前,我们正在缓存特定网页上的区域特定内容。 例如:

  Page 123区域A 

将有不同的内容 \ n

  Page 123区域B 



  1. 存储/检索指定用户的区域ID的最佳方法是什么? \ n
  2. 存储/检索指定区域ID的页面/视图的关联数据的最佳方法是什么?


  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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.

    解决 无用
    打赏 举报

相关推荐 更多相似问题