Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schmidt/cache_annotations
old experiment to implement active_support's memoize before a_s came up with it
https://github.com/schmidt/cache_annotations
Last synced: 30 days ago
JSON representation
old experiment to implement active_support's memoize before a_s came up with it
- Host: GitHub
- URL: https://github.com/schmidt/cache_annotations
- Owner: schmidt
- License: mit
- Created: 2009-12-03T22:41:21.000Z (almost 15 years ago)
- Default Branch: master
- Last Pushed: 2009-12-03T23:01:15.000Z (almost 15 years ago)
- Last Synced: 2024-09-17T15:58:17.075Z (about 2 months ago)
- Language: Ruby
- Homepage:
- Size: 89.8 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.rdoc
- Changelog: History.txt
- License: License.txt
Awesome Lists containing this project
README
With CacheAnnotation you may easily provide your methods with an often needed
caching. Suppose you are using the following piece of code:class A
def a
@a ||= "some heavy computing that should be done only once"
end
endThis could look so much better:
class A
include CacheAnnotationcached
def a
"some heavy computing that should be done only once"
end
endOr even better for single argumented methods:
class A
def b(arg0)
@b ||= {}
@b[arg0] ||= "some heavy computing in respect to #{arg0} " +
"that should be done only once"
end
endvs.
class A
include CacheAnnotationcached
def b(arg0)
"some heavy computing in respect to #{arg0} " +
"that should be done only once"
end
endBehind the scenes, CacheAnnotation replaces the method body with the caching
code. So the two versions are equal concerning behaviour and speed. If you
don't want CacheAnnotation to derive the instance variable's name from the
method name, you may supply a custom one:class A
include CacheAnnotationcached :in => :@b_cache
def b(arg0)
"some heavy computing in respect to #{arg0} " +
"that should be done only once"
end
endIf you want to use CacheAnnotation on the class side, you have to use a
special technique to add these methods. It is described pretty good on
http://www.dcmanges.com/blog/27class A
module ClassMethods
include CacheAnnotationcached
def c
"some heavy computing that should be done only once"
end
end
self.extend(ClassMethods)
end