This project is archived and is in readonly mode.
Per-request in memory cache for all communication with the MemCache server(s)
-
Nahum Wild
Ah, it's not thread safe - working on that now.
-
Jeffrey Hardy
I totally dig the idea of this. It's similar to what Nick Kallen's cache_money plugin does:
http://github.com/nkallen/cache-...
The main thing that bothers me about the implementation in this patch is that it knows about Action Controller. The cache store shouldn't know Action Controller even exists. I'd much rather there be a facility to tell the cache store to use the local cache or not, such that we could declare the setting from AC's side.
-
Nahum Wild
Jeffrey, I totally agree with you on the subject of the class knowing about ActionController. In fact my delay in updating this ticket with a thread safe version is because I've been trying to solve that problem nicely.
I like simply going:
config.action_controller.session_store = :mem_cache_store
to setup memcache in rails. I don't really want people to have to do extra things to get it going when it should just work seamlessly without any effort. At the moment it still depends on AC.
Doing the local caching actually solves a bug in rails, something I've not directly said above. It stops the problem of entries in memcache changing in between the execution of the action and view code. I've had this happen a number of times, pain in the butt to track down. I probably should have tagged this with bug too maybe...
Anyway, I've attached an updated patch with my changes being thread safe now plus a minor fix to the 'exist?' method.
-
Nahum Wild
Just to clariy for those reading, the dependency on ActionController is because MemCacheStore hooks into the Dispatcher before_dispatch callback to clear the local cache before each request is processed.
-
josh
- Milestone cleared.
- State changed from new to open
I think a middleware hook would be most appropriate.
use ActiveSupport::Cache::MemCacheStore::LocalCache # or Buffering
You could have the middleware initialize and reset the local cache as well. Otherwise the cache store could function standalone without the local buffer.
-
Repository
- State changed from open to resolved
(from [a53ad5bba37199047ba20194933e122bf6b0252f]) Added in a local per request cache to MemCacheStore. It acts as a buffer to stop unneccessary requests being sent through to memcache [#1653 Per-request in memory cache for all communication with the MemCache server(s) state:resolved] Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
-
josh
Hey, I just commit it.
I made some changes, it uses a thread local instead of a lock. Should be much less overhead.
Please review and make sure it still functions how you want.
-
Nahum Wild
Will do thanks for doing that. I'll look at it right now. (Clients discovered I had spare time :-(
-
Nahum Wild
Yep, functions as intended. :-)
-
Nahum Wild
Oh and thanks for giving it some polish Joshua.
-
josh
Interesting comments on github:
http://github.com/rails/rails/co...
Maybe it should be a subclass or extension module?
-
Lourens Naudé
Josh,
Initial backend agnostic local cache strategy attached.Introduced an ActiveSupport::Cache::Strategy::* namespace, which may be frowned upon, but may be useful for similar optimizations.
Original test cases passes.
-
josh
- State changed from resolved to open
@Lourens Thanks
I think it can be implemented cleaner with extend and super. I'll take care of that though.
Thanks for the patch, will commit soon.
-
Repository
- State changed from open to resolved
(from [b08c96887538cf53670bb882e79996582375e6c9]) Decouple the local cache strategy from MemCacheStore for reuse with other remote stores [#1653 Per-request in memory cache for all communication with the MemCache server(s) state:resolved]
Signed-off-by: Joshua Peek josh@joshpeek.com http://github.com/rails/rails/co...
-
Lourens Naudé
@ Josh,
Am aware of two apps where the immutable snippet in #read raises with TypeError when the value being dup'ed is a special case constant eg. Fixnum, TrueClass etc.
Here's the reference to the MRI implementation of Object#clone, Object#dup ( object.c ) && the special constant declaration ( ruby.h ) from a 187 checkout :
Attached is a patch that implements Object#dup? to better handle such cases.
Thoughts ?
- Lourens
-
Lourens Naudé
Updated diff for Object#clone?
-
josh
Maybe we could just add dup to Integer and just return self?
-
Lourens Naudé
@ Josh,
Interesting, but isn't it dodgy practice to mask the TypeError in non-framework code VS being able to conditionally guard against it in specific framework areas, like the local cache, to not blow up the whole process when that happens ?
-
Lourens Naudé
Josh,
Nevermind, references :
"* object.duplicable? returns true if object.dup is safe. False for nil, true, false, symbols, and numbers; true otherwise. #9333 [sur]"
Patch that piggy backs on that attached.
-
Repository
(from [2e69db18ce2815c25eee64fc2978e7f6b57f6e1f]) Only dup local cache values if duplicable [#1653 Per-request in memory cache for all communication with the MemCache server(s) state:resolved] http://github.com/rails/rails/co...
