CachedSupermodel 0.1.2.10 → 0.1.2.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.txt +66 -3
- data/Rakefile +1 -1
- data/lib/cs_active_record.rb +5 -1
- metadata +3 -3
data/README.txt
CHANGED
@@ -39,15 +39,78 @@ Then, when run, that query will be cached.
|
|
39
39
|
|
40
40
|
== SYNOPSYS:
|
41
41
|
|
42
|
-
|
42
|
+
To completely remove most of your SQL read queries, this is what you write (basically) in your environment.rb.
|
43
|
+
|
44
|
+
I use the caffeine gem here to get as speedy access to the memcache servers as possible, just 'gem install caffeine' for that.
|
45
|
+
|
46
|
+
Also, you need to install the memcache_client gem ('gem install memcache_client') because otherwise rails will assume (stupid
|
47
|
+
as it is) that you can't use memcache for sessions.
|
48
|
+
|
49
|
+
-------------------8<--------------------
|
50
|
+
|
51
|
+
# require the necessary gems
|
52
|
+
require 'caffeine'
|
53
|
+
require 'adocca_memcache'
|
54
|
+
require 'cached_supermodel'
|
55
|
+
|
56
|
+
# Set the base time to live to "forever"
|
57
|
+
ActiveRecord::Base.ttl = 0
|
58
|
+
|
59
|
+
# default memcache options
|
60
|
+
# including a separate namespace for each environment (dev, prod, test).
|
61
|
+
# (if you want to run several apps on the same memcache servers i suggest also adding the app name to the namespace...)
|
62
|
+
memcache_options = {
|
63
|
+
:c_threshold => 10_000,
|
64
|
+
:compression => false,
|
65
|
+
:debug => false,
|
66
|
+
:namespace => "#{RAILS_ENV}",
|
67
|
+
:readonly => false,
|
68
|
+
:urlencode => false
|
69
|
+
}
|
70
|
+
|
71
|
+
# The default CACHE object used by pretty much everything
|
72
|
+
CACHE = Caffeine::MemCache.new memcache_options
|
73
|
+
# Let our magical synchronization lock know about this cache
|
74
|
+
Adocca::Synchronized::CACHE = CACHE
|
75
|
+
# set the cache servers to localhost (please, dont forget to actually run a memcache server wherever you set this to :)
|
76
|
+
CACHE.servers = ['localhost:11211']
|
77
|
+
|
78
|
+
#
|
79
|
+
# Let the sessions be stored in a separate memcached instance
|
80
|
+
# This way we can easily flush the cache for the application-servers
|
81
|
+
# without destroying the sessions.
|
82
|
+
#
|
83
|
+
CACHE_SESSION = Caffeine::MemCache.new memcache_options
|
84
|
+
CACHE_SESSION.servers = ['localhost:11211']
|
85
|
+
|
86
|
+
# User is considered offline after N mins
|
87
|
+
$SESSION_TIMEOUT = 12.hours
|
88
|
+
|
89
|
+
# create a nicely reachable constant for the session options
|
90
|
+
DEFAULT_SESSION_OPTIONS = ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS
|
91
|
+
DEFAULT_SESSION_OPTIONS.delete(:session_expires)
|
92
|
+
# use the session memcache for sessions unless we are doing this in the test environment,
|
93
|
+
# in which case i experienced some problems with this...
|
94
|
+
DEFAULT_SESSION_OPTIONS.update({
|
95
|
+
:database_manager => CGI::Session::MemCacheStore,
|
96
|
+
:cache => CACHE_SESSION,
|
97
|
+
:expires => $SESSION_TIMEOUT
|
98
|
+
}) unless RAILS_ENV == 'test'
|
99
|
+
|
100
|
+
--------------------8<-------------------------
|
43
101
|
|
44
102
|
== REQUIREMENTS:
|
45
103
|
|
46
|
-
*
|
104
|
+
* AdoccaMemcache
|
47
105
|
|
48
106
|
== INSTALL:
|
49
107
|
|
50
|
-
|
108
|
+
sudo gem install CachedSupermodel
|
109
|
+
sudo gem install memcache_client
|
110
|
+
|
111
|
+
(recommended)
|
112
|
+
|
113
|
+
sudo gem install caffeine
|
51
114
|
|
52
115
|
== LICENSE:
|
53
116
|
|
data/Rakefile
CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
|
|
4
4
|
require 'hoe'
|
5
5
|
require './lib/cached_supermodel.rb'
|
6
6
|
|
7
|
-
Hoe.new('CachedSupermodel', '0.1.2.
|
7
|
+
Hoe.new('CachedSupermodel', '0.1.2.11') do |p|
|
8
8
|
p.summary = 'A library that automatically caches all ActiveRecord::Base instances in memcache using the AdoccaMemcache gem.'
|
9
9
|
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
10
10
|
p.author = 'adocca Entertainment AB'
|
data/lib/cs_active_record.rb
CHANGED
@@ -360,9 +360,13 @@ before_destroy :invalidate_cached_#{finder}
|
|
360
360
|
|
361
361
|
##
|
362
362
|
# The local cache key for this record.
|
363
|
+
# If this class is STI, store the record as the top-level class instead.
|
364
|
+
# Otherwise we will have uncached queries when STI-records are stored as polymorphic assocations
|
365
|
+
|
363
366
|
|
364
367
|
def self.cache_key_local(klass, id)
|
365
|
-
|
368
|
+
klass = Module.const_get(klass) unless Class === klass
|
369
|
+
return "#{klass.base_class.name}:#{id}"
|
366
370
|
end
|
367
371
|
|
368
372
|
def cache_key_local
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: CachedSupermodel
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.2.
|
7
|
-
date:
|
6
|
+
version: 0.1.2.11
|
7
|
+
date: 2008-01-22 00:00:00 +01:00
|
8
8
|
summary: A library that automatically caches all ActiveRecord::Base instances in memcache using the AdoccaMemcache gem.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -70,5 +70,5 @@ dependencies:
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version: 1.
|
73
|
+
version: 1.4.0
|
74
74
|
version:
|