Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Strategy::LocalCache doesn't work with multiple caching methods

#3597

I'm using Strategy::LocalCache to provide solely a per-request local cache (by implementing a caching strategy that extends LocalCache but does nothing itself). When I upgraded from 2.3.4 -> 2.3.5, LocalCache stopped working.

The problem is that when the klass is created in middleware, the thread_local_key is evaluated once at load, and is fixed as that no matter where it is used. In this case, it is fixed at active_support_mem_cache_store_local_cache.

At runtime, it uses a key for whatever class is currently being used; in my case, active_support_request_store_local_cache. Therefore it doesn't match the key that was used to set up a new MemoryStore; and it always results in a nil local_cache.

The end result is that LocalCache only works if you use it for a single cache store, but fails if you try it use it for another one.

Test cache implementation is attached; put this file in lib/active_support_cache and try to use RequestStore as your caching strategy -- it will always fail to find the key you just put in the cache. It should find the key if the read is within the same request as the write; and fail only if it is across requests.

Reported by jeffsc · December 18th, 2009 @ 08:28 PM

State: wontfix
Milestone: none
Assigned to: josh josh
Importance: Low

Activity

  1. josh
    josh
    • State changed from new to incomplete

    LocalCache was only designed to work with Memcache. Its interesting that it sort of works in other cases. If you come up with a fix, I'd gladly commit.

    December 20th, 2009 @ 10:58 PM

  2. josh
    josh
    • State changed from incomplete to wontfix

    December 20th, 2009 @ 10:58 PM