djmaze-arid_cache 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +26 -0
- data/Gemfile +18 -0
- data/LICENSE +20 -0
- data/README.rdoc +394 -0
- data/Rakefile +78 -0
- data/VERSION +1 -0
- data/arid_cache.gemspec +104 -0
- data/init.rb +6 -0
- data/lib/arid_cache/active_record.rb +95 -0
- data/lib/arid_cache/cache_proxy.rb +368 -0
- data/lib/arid_cache/helpers.rb +86 -0
- data/lib/arid_cache/store.rb +125 -0
- data/lib/arid_cache.rb +47 -0
- data/rails/init.rb +1 -0
- data/spec/arid_cache/arid_cache_spec.rb +39 -0
- data/spec/arid_cache/cache_proxy_result_spec.rb +53 -0
- data/spec/arid_cache/cache_proxy_spec.rb +95 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +29 -0
- data/spec/support/ar_query.rb +128 -0
- data/spec/support/custom_methods.rb +7 -0
- data/spec/support/matchers.rb +33 -0
- data/test/arid_cache_test.rb +414 -0
- data/test/console +15 -0
- data/test/lib/add_query_counting_to_active_record.rb +11 -0
- data/test/lib/blueprint.rb +29 -0
- data/test/lib/db_prepare.rb +34 -0
- data/test/lib/fix_active_support_file_store_expires_in.rb +18 -0
- data/test/lib/mock_rails.rb +29 -0
- data/test/lib/models/company.rb +6 -0
- data/test/lib/models/empty_user_relation.rb +5 -0
- data/test/lib/models/user.rb +32 -0
- data/test/log/.gitignore +0 -0
- data/test/test_helper.rb +19 -0
- metadata +177 -0
data/test/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler/setup'
|
5
|
+
Bundler.require
|
6
|
+
require 'mock_rails'
|
7
|
+
require 'blueprint'
|
8
|
+
require 'irb'
|
9
|
+
|
10
|
+
WillPaginate.enable_activerecord
|
11
|
+
AridCache.init_rails
|
12
|
+
Blueprint.seeds
|
13
|
+
|
14
|
+
ARGV.clear
|
15
|
+
IRB.start
|
@@ -0,0 +1,11 @@
|
|
1
|
+
class << ActiveRecord::Base.connection
|
2
|
+
IGNORED_SQL = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SHOW FIELDS /]
|
3
|
+
|
4
|
+
def execute_with_counting(sql, name = nil, &block)
|
5
|
+
$query_count ||= 0
|
6
|
+
$query_count += 1 unless IGNORED_SQL.any? { |r| sql =~ r }
|
7
|
+
execute_without_counting(sql, name, &block)
|
8
|
+
end
|
9
|
+
|
10
|
+
alias_method_chain :execute, :counting
|
11
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'machinist/active_record'
|
2
|
+
require 'sham'
|
3
|
+
require 'faker'
|
4
|
+
|
5
|
+
Sham.name { Faker::Name.name }
|
6
|
+
Sham.company_name { Faker::Company.name }
|
7
|
+
Sham.email { Faker::Internet.email }
|
8
|
+
|
9
|
+
User.blueprint do
|
10
|
+
name
|
11
|
+
email
|
12
|
+
end
|
13
|
+
|
14
|
+
Company.blueprint do
|
15
|
+
name { Sham.company_name }
|
16
|
+
employees { rand(200) }
|
17
|
+
#owner
|
18
|
+
end
|
19
|
+
|
20
|
+
module Blueprint
|
21
|
+
def self.seeds
|
22
|
+
10.times do
|
23
|
+
user = User.make
|
24
|
+
(5 + rand(5)).times do
|
25
|
+
Company.make(:owner => user)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'active_record'
|
2
|
+
|
3
|
+
# Create an in-memory sqlite3 database
|
4
|
+
ActiveRecord::Base.establish_connection(
|
5
|
+
:adapter => "sqlite3",
|
6
|
+
:database => ":memory:"
|
7
|
+
)
|
8
|
+
|
9
|
+
# Schema
|
10
|
+
ActiveRecord::Base.silence do
|
11
|
+
ActiveRecord::Migration.verbose = false
|
12
|
+
|
13
|
+
ActiveRecord::Schema.define do
|
14
|
+
create_table "users", :force => true do |t|
|
15
|
+
t.column "name", :text
|
16
|
+
t.column "email", :text
|
17
|
+
t.timestamps
|
18
|
+
end
|
19
|
+
|
20
|
+
create_table "companies", :force => true do |t|
|
21
|
+
t.column "name", :text
|
22
|
+
t.column "owner_id", :integer
|
23
|
+
t.column "country_id", :integer
|
24
|
+
t.column "employees", :integer
|
25
|
+
t.timestamps
|
26
|
+
end
|
27
|
+
|
28
|
+
create_table "empty_user_relations", :force => true do |t|
|
29
|
+
t.column "user_id", :integer
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
Dir[File.join(File.dirname(__FILE__), 'models', '*.rb')].each { |f| require f }
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# Add support for expiring file-cache store.
|
2
|
+
|
3
|
+
module ActiveSupport
|
4
|
+
module Cache
|
5
|
+
class FileStore < Store
|
6
|
+
alias :original_read :read
|
7
|
+
|
8
|
+
def read(name, options = {})
|
9
|
+
lastmod = File.mtime(real_file_path(name)) rescue nil
|
10
|
+
if lastmod && options.is_a?(Hash) && options[:expires_in] && ((lastmod + options[:expires_in]) <= Time.now)
|
11
|
+
nil
|
12
|
+
else
|
13
|
+
original_read(name, options)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'logger'
|
2
|
+
require 'fix_active_support_file_store_expires_in'
|
3
|
+
|
4
|
+
root_path = File.expand_path(File.join(File.dirname(__FILE__), '../../'))
|
5
|
+
RAILS_DEFAULT_LOGGER = ENV["STDOUT"] ? Logger.new(STDOUT) : Logger.new(File.join(root_path, '/test/log/test.log'))
|
6
|
+
RAILS_CACHE = ActiveSupport::Cache.lookup_store(:file_store, File.join(root_path, '/tmp/cache'))
|
7
|
+
|
8
|
+
# Mock Rails
|
9
|
+
Rails = Class.new do
|
10
|
+
cattr_accessor :logger, :cache
|
11
|
+
def self.cache
|
12
|
+
return RAILS_CACHE
|
13
|
+
end
|
14
|
+
def self.logger
|
15
|
+
return RAILS_DEFAULT_LOGGER
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# Set loggers for all frameworks
|
20
|
+
for framework in ([ :active_record, :action_controller, :action_mailer ])
|
21
|
+
if Object.const_defined?(framework.to_s.camelize)
|
22
|
+
framework.to_s.camelize.constantize.const_get("Base").logger = Rails.logger
|
23
|
+
end
|
24
|
+
end
|
25
|
+
ActiveSupport::Dependencies.logger = Rails.logger
|
26
|
+
Rails.cache.logger = Rails.logger
|
27
|
+
|
28
|
+
# Include this last otherwise the logger isn't set properly
|
29
|
+
require 'db_prepare'
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'arid_cache'
|
2
|
+
|
3
|
+
class User < ActiveRecord::Base
|
4
|
+
has_many :companies, :foreign_key => :owner_id
|
5
|
+
has_many :empty_user_relations # This must always return an empty list
|
6
|
+
named_scope :companies, :joins => :companies
|
7
|
+
named_scope :successful, :joins => :companies, :conditions => 'companies.employees > 50', :group => 'users.id'
|
8
|
+
|
9
|
+
def big_companies
|
10
|
+
companies.find :all, :conditions => [ 'employees > 20' ]
|
11
|
+
end
|
12
|
+
|
13
|
+
def pet_names
|
14
|
+
['Fuzzy', 'Peachy']
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing(method, *args)
|
18
|
+
if method == :is_high?
|
19
|
+
true
|
20
|
+
else
|
21
|
+
super
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def respond_to?(method)
|
26
|
+
if method == :respond_not_overridden
|
27
|
+
true
|
28
|
+
else
|
29
|
+
super
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/log/.gitignore
ADDED
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), 'lib')) # make requiring from test/lib easy
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/setup'
|
6
|
+
Bundler.require
|
7
|
+
require 'test/unit' # required by ActiveSupport::TestCase
|
8
|
+
require 'active_support/test_case'
|
9
|
+
|
10
|
+
require 'mock_rails'
|
11
|
+
require 'blueprint'
|
12
|
+
require 'add_query_counting_to_active_record'
|
13
|
+
|
14
|
+
WillPaginate.enable_activerecord
|
15
|
+
AridCache.init_rails
|
16
|
+
Blueprint.seeds
|
17
|
+
|
18
|
+
ActiveRecord::Base.logger.info("#{"="*25} RUNNING UNIT TESTS #{"="*25}\n\t\t\t#{Time.now.to_s}\n#{"="*70}")
|
19
|
+
Array.class_eval { alias count size } if RUBY_VERSION < '1.8.7'
|
metadata
ADDED
@@ -0,0 +1,177 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: djmaze-arid_cache
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 19
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 1.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Karl Varga
|
14
|
+
- Martin Honermeyer
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2011-02-18 00:00:00 +01:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: will_paginate
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
prerelease: false
|
34
|
+
type: :runtime
|
35
|
+
requirement: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: will_paginate
|
38
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
prerelease: false
|
48
|
+
type: :development
|
49
|
+
requirement: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: faker
|
52
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
hash: 3
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
61
|
+
prerelease: false
|
62
|
+
type: :development
|
63
|
+
requirement: *id003
|
64
|
+
- !ruby/object:Gem::Dependency
|
65
|
+
name: machinist
|
66
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
prerelease: false
|
76
|
+
type: :development
|
77
|
+
requirement: *id004
|
78
|
+
description: |
|
79
|
+
Fork of arid_cache which defines caching methods once on a class instead of per object, thus preventing "singleton can't be dumped" from memcached!
|
80
|
+
AridCache makes caching easy and effective. AridCache supports caching on all your model named scopes, class methods and instance methods right out of the box. AridCache prevents caching logic from cluttering your models and clarifies your logic by making explicit calls to cached result sets.
|
81
|
+
AridCache is designed for handling large, expensive ActiveRecord collections but is equally useful for caching anything else as well.
|
82
|
+
|
83
|
+
email: maze@strahlungsfrei.de
|
84
|
+
executables: []
|
85
|
+
|
86
|
+
extensions: []
|
87
|
+
|
88
|
+
extra_rdoc_files:
|
89
|
+
- LICENSE
|
90
|
+
- README.rdoc
|
91
|
+
files:
|
92
|
+
- .gitignore
|
93
|
+
- Gemfile
|
94
|
+
- LICENSE
|
95
|
+
- README.rdoc
|
96
|
+
- Rakefile
|
97
|
+
- VERSION
|
98
|
+
- arid_cache.gemspec
|
99
|
+
- init.rb
|
100
|
+
- lib/arid_cache.rb
|
101
|
+
- lib/arid_cache/active_record.rb
|
102
|
+
- lib/arid_cache/cache_proxy.rb
|
103
|
+
- lib/arid_cache/helpers.rb
|
104
|
+
- lib/arid_cache/store.rb
|
105
|
+
- rails/init.rb
|
106
|
+
- spec/arid_cache/arid_cache_spec.rb
|
107
|
+
- spec/arid_cache/cache_proxy_result_spec.rb
|
108
|
+
- spec/arid_cache/cache_proxy_spec.rb
|
109
|
+
- spec/spec.opts
|
110
|
+
- spec/spec_helper.rb
|
111
|
+
- spec/support/ar_query.rb
|
112
|
+
- spec/support/custom_methods.rb
|
113
|
+
- spec/support/matchers.rb
|
114
|
+
- test/arid_cache_test.rb
|
115
|
+
- test/console
|
116
|
+
- test/lib/add_query_counting_to_active_record.rb
|
117
|
+
- test/lib/blueprint.rb
|
118
|
+
- test/lib/db_prepare.rb
|
119
|
+
- test/lib/fix_active_support_file_store_expires_in.rb
|
120
|
+
- test/lib/mock_rails.rb
|
121
|
+
- test/lib/models/company.rb
|
122
|
+
- test/lib/models/empty_user_relation.rb
|
123
|
+
- test/lib/models/user.rb
|
124
|
+
- test/log/.gitignore
|
125
|
+
- test/test_helper.rb
|
126
|
+
has_rdoc: true
|
127
|
+
homepage: http://github.com/djmaze/arid_cache
|
128
|
+
licenses: []
|
129
|
+
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options:
|
132
|
+
- --charset=UTF-8
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
hash: 3
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
version: "0"
|
144
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
hash: 3
|
150
|
+
segments:
|
151
|
+
- 0
|
152
|
+
version: "0"
|
153
|
+
requirements: []
|
154
|
+
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 1.5.2
|
157
|
+
signing_key:
|
158
|
+
specification_version: 3
|
159
|
+
summary: Automates efficient caching of your ActiveRecord collections, gives you counts for free and supports pagination.
|
160
|
+
test_files:
|
161
|
+
- spec/spec_helper.rb
|
162
|
+
- spec/arid_cache/cache_proxy_result_spec.rb
|
163
|
+
- spec/arid_cache/cache_proxy_spec.rb
|
164
|
+
- spec/arid_cache/arid_cache_spec.rb
|
165
|
+
- spec/support/matchers.rb
|
166
|
+
- spec/support/custom_methods.rb
|
167
|
+
- spec/support/ar_query.rb
|
168
|
+
- test/lib/add_query_counting_to_active_record.rb
|
169
|
+
- test/lib/models/company.rb
|
170
|
+
- test/lib/models/empty_user_relation.rb
|
171
|
+
- test/lib/models/user.rb
|
172
|
+
- test/lib/mock_rails.rb
|
173
|
+
- test/lib/fix_active_support_file_store_expires_in.rb
|
174
|
+
- test/lib/db_prepare.rb
|
175
|
+
- test/lib/blueprint.rb
|
176
|
+
- test/test_helper.rb
|
177
|
+
- test/arid_cache_test.rb
|