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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?