public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added Memoizable mixin for caching simple lazy loaded attributes
josh (author)
Mon Jul 14 17:50:32 -0700 2008
commit  8a9934a9d9fc98b56c4566ae2e3fd4d83e505d3e
tree    fe7ed2626140178c722f5245d37b23c311da5ce4
parent  d27dd860c7f4f9b9e5aebe7d0c6e9b6108d8717c
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *Edge*
0
 
0
+* Added Memoizable mixin for caching simple lazy loaded attributes [Josh Peek]
0
+
0
 * Move the test related core_ext stuff out of core_ext so it's only loaded by the test helpers.  [Michael Koziarski]
0
 
0
 * Add Inflection rules for String#humanize. #535 [dcmanges]
...
43
44
45
 
46
47
48
...
43
44
45
46
47
48
49
0
@@ -43,6 +43,7 @@ require 'active_support/ordered_hash'
0
 require 'active_support/ordered_options'
0
 require 'active_support/option_merger'
0
 
0
+require 'active_support/memoizable'
0
 require 'active_support/string_inquirer'
0
 
0
 require 'active_support/values/time_zone'

Comments

timocratic Tue Jul 15 19:09:15 -0700 2008

Is the inconsistency between memoize (the usage I am used to and used in the file name and the module name) and memorize (the actual call) intentional?

josh Tue Jul 15 22:09:25 -0700 2008

It was fixed in 001c8beb4

matthewrudy Wed Jul 16 01:54:56 -0700 2008

why doesn’t it use alias_method_chain? or atleast the same structure of aliasing.

with this we get a non-standard name for the function that bypasses memoizing.

I’d also want a .blah(true) which would force reload

humanzz Wed Jul 16 05:23:15 -0700 2008

I have previously implemented the memoize feature as method_cache plugin at http://github.com/humanzz/method_cache. But method_cache had a couple more features: in addition to caching results in instance variables it also stored the result in the cache store. It’d be great if memoize adds such feature.

josh Wed Jul 16 10:16:10 -0700 2008

@matthewruby I’m trying to avoid alias_method_chain. But if access to the original method is important, maybe we could name it “name_without_memoization”.

@humanzz No to RAILS_CACHE. Most of time you a memorizing simple string manipulations or integer calculations. They are either short lived and should die with the object or long live and you want to deal with the memcache protocol latency.

michaelklishin Wed Jul 16 18:12:49 -0700 2008

Very valuable addition, definitely needed to go in as a separate module while patches that fix 500 problem with Nginx proxying get dusty.

michaelklishin Wed Jul 16 18:16:10 -0700 2008

and I like the way alias method chain is avoided here.

michaelklishin Wed Jul 16 18:16:14 -0700 2008

and I like the way alias method chain is avoided here.

josh Wed Jul 16 19:28:56 -0700 2008

BTW, this is module is NOT include anywhere by default. To use it include ActiveSupport::Memoizable

nbibler Fri Jul 18 06:06:39 -0700 2008

As far as implementations go, this is alright, but there doesn’t appear to be a simple way to reload the data. Personally, I like Marcel Molina’s implementation of this same feature in the AWS-S3 library.

josh Fri Jul 18 09:18:00 -0700 2008

I didn’t realize that amount of people who would be using this outside of core. I added a few of your requests.

http://github.com/rails/rails/commit/e1f23da53cef20a60e4bf458d959fe2bfe7d52ea