Include this module in your Og managed classes to make them cacheable. Only queries by id are cached.

If you use a distributed cache (drb, memcache, etc) , you may have to start a separate server.

Methods
Public Class methods
cache_delete(klass, pk)

Invalidate the cache entry for an object. Og high level methods automatically call this method where needed. However if you manually alter the store using Og low level methods (for example a native SQL query) you should call this method explicitly.

     # File lib/og/model/cacheable.rb, line 144
144:   def self.cache_delete(klass, pk)
145:     #key = "og#{klass}:#{pk}"
146:     key = klass.og_cache_key(pk)
147: #   self.og_local_cache.delete(key)
148:     klass.ogmanager.cache.delete(key)
149:   end
cache_get(klass, pk)

     # File lib/og/model/cacheable.rb, line 128
128:   def self.cache_get(klass, pk)
129:     obj.class.ogmanager.cache.get(klass.og_cache_key(pk)) 
130:   end
cache_set(obj)

     # File lib/og/model/cacheable.rb, line 134
134:   def self.cache_set(obj)
135:     obj.class.ogmanager.cache.set(obj.og_cache_key, obj)         
136:   end
delete(obj_or_pk, cascade = true)
     # File lib/og/model/cacheable.rb, line 110
110:           def delete(obj_or_pk, cascade = true)
111:             delete_without_cache(obj_or_pk, cascade)
112:             Cacheable.cache_delete(self, obj_or_pk)
113:           end
load(pk)
     # File lib/og/model/cacheable.rb, line 97
 97:           def load(pk)
 98:             key = og_cache_key(pk)
 99:             unless obj = ogmanager.cache.get(key)
100:               obj = load_without_cache(pk)
101:               ogmanager.cache.set(key, obj)
102:             end
103:             
104:             return obj
105:           end
og_cache_key(pk)
     # File lib/og/model/cacheable.rb, line 115
115:           def og_cache_key(pk)
116:             "#{self}:#{pk}"  
117:           end
Public Instance methods
after_enchant(base)
     # File lib/og/model/cacheable.rb, line 21
 21:     def after_enchant(base)
 22:       base.module_eval do
 23: 
 24:         alias_method :save_without_cache, :save      
 25:         def save(options = nil)
 26:           Cacheable.cache_delete(self.class, pk)
 27:           val = save_without_cache(options)
 28:           Cacheable.cache_set(self)
 29:           return val
 30:         end
 31:         alias_method :save!, :save
 32:         alias_method :validate_and_save, :save
 33: 
 34:         alias_method :force_save_without_cache!, :force_save!      
 35:         def force_save!(options = nil)
 36:           Cacheable.cache_delete(self.class, pk)
 37:           val = force_save_without_cache!(options)
 38:           Cacheable.cache_set(self)
 39:           return val
 40:         end
 41: 
 42:         alias_method :insert_without_cache, :insert      
 43:         def insert
 44:           insert_without_cache()
 45:           Cacheable.cache_set(self)
 46:           return self
 47:         end
 48: 
 49:         alias_method :update_without_cache, :update      
 50:         def update(options = nil)
 51:           Cacheable.cache_delete(self.class, pk)
 52:           val = update_without_cache(options)
 53:           Cacheable.cache_set(self)
 54:           return val
 55:         end
 56: 
 57:         alias_method :update_properties_without_cache, :update_properties      
 58:         def update_properties(*properties)
 59:           Cacheable.cache_delete(self.class, pk)
 60:           val = update_properties_without_cache(*properties)
 61:           Cacheable.cache_set(self)
 62:           return val
 63:         end
 64:         alias_method :update_property, :update_properties
 65:         alias_method :pupdate, :update_properties
 66: 
 67:         alias_method :update_by_sql_without_cache, :update_by_sql      
 68:         def update_by_sql(set)
 69:           Cacheable.cache_delete(self.class, pk)
 70:           val = update_by_sql_without_cache(sql)
 71:           Cacheable.cache_set(self)
 72:           return val
 73:         end
 74:         alias_method :update_sql, :update_by_sql
 75:         alias_method :supdate, :update_by_sql
 76: 
 77:         alias_method :reload_without_cache, :reload      
 78:         def reload
 79:           Cacheable.cache_delete(self.class, pk)
 80:           reload_without_cache()
 81:           Cacheable.cache_set(self)
 82:         end
 83:         alias_method :reload!, :reload
 84: 
 85:         alias_method :delete_without_cache, :delete      
 86:         def delete(cascade = true)
 87:           delete_without_cache(cascade)
 88:           Cacheable.cache_delete(self.class, pk)
 89:         end
 90:         
 91:         def og_cache_key
 92:           "#{self.class}:#{pk}"
 93:         end
 94:         
 95:         class << self
 96:           alias_method :load_without_cache, :load
 97:           def load(pk)
 98:             key = og_cache_key(pk)
 99:             unless obj = ogmanager.cache.get(key)
100:               obj = load_without_cache(pk)
101:               ogmanager.cache.set(key, obj)
102:             end
103:             
104:             return obj
105:           end
106:           alias_method :[], :load
107:           alias_method :exist?, :load
108:           
109:           alias_method :delete_without_cache, :delete      
110:           def delete(obj_or_pk, cascade = true)
111:             delete_without_cache(obj_or_pk, cascade)
112:             Cacheable.cache_delete(self, obj_or_pk)
113:           end
114:           
115:           def og_cache_key(pk)
116:             "#{self}:#{pk}"  
117:           end          
118:                     
119:         end
120:         
121:       end
122:     end
delete(cascade = true)
This method is also aliased as delete_without_cache
    # File lib/og/model/cacheable.rb, line 86
86:         def delete(cascade = true)
87:           delete_without_cache(cascade)
88:           Cacheable.cache_delete(self.class, pk)
89:         end
delete_without_cache(cascade = true)

Alias for #delete

force_save!(options = nil)
    # File lib/og/model/cacheable.rb, line 35
35:         def force_save!(options = nil)
36:           Cacheable.cache_delete(self.class, pk)
37:           val = force_save_without_cache!(options)
38:           Cacheable.cache_set(self)
39:           return val
40:         end
insert()
    # File lib/og/model/cacheable.rb, line 43
43:         def insert
44:           insert_without_cache()
45:           Cacheable.cache_set(self)
46:           return self
47:         end
og_cache_key()
    # File lib/og/model/cacheable.rb, line 91
91:         def og_cache_key
92:           "#{self.class}:#{pk}"
93:         end
reload()
    # File lib/og/model/cacheable.rb, line 78
78:         def reload
79:           Cacheable.cache_delete(self.class, pk)
80:           reload_without_cache()
81:           Cacheable.cache_set(self)
82:         end
save(options = nil)
    # File lib/og/model/cacheable.rb, line 25
25:         def save(options = nil)
26:           Cacheable.cache_delete(self.class, pk)
27:           val = save_without_cache(options)
28:           Cacheable.cache_set(self)
29:           return val
30:         end
update(options = nil)
    # File lib/og/model/cacheable.rb, line 50
50:         def update(options = nil)
51:           Cacheable.cache_delete(self.class, pk)
52:           val = update_without_cache(options)
53:           Cacheable.cache_set(self)
54:           return val
55:         end
update_by_sql(set)
    # File lib/og/model/cacheable.rb, line 68
68:         def update_by_sql(set)
69:           Cacheable.cache_delete(self.class, pk)
70:           val = update_by_sql_without_cache(sql)
71:           Cacheable.cache_set(self)
72:           return val
73:         end
update_properties(*properties)
    # File lib/og/model/cacheable.rb, line 58
58:         def update_properties(*properties)
59:           Cacheable.cache_delete(self.class, pk)
60:           val = update_properties_without_cache(*properties)
61:           Cacheable.cache_set(self)
62:           return val
63:         end