identity_cache 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +1 -0
- data/CHANGELOG +7 -0
- data/README.md +8 -0
- data/Rakefile +19 -0
- data/identity_cache.gemspec +2 -1
- data/lib/{belongs_to_caching.rb → identity_cache/belongs_to_caching.rb} +12 -8
- data/lib/identity_cache/cache_key_generation.rb +58 -0
- data/lib/identity_cache/configuration_dsl.rb +301 -0
- data/lib/identity_cache/memoized_cache_proxy.rb +118 -0
- data/lib/identity_cache/parent_model_expiration.rb +34 -0
- data/lib/identity_cache/query_api.rb +312 -0
- data/lib/identity_cache/version.rb +1 -1
- data/lib/identity_cache.rb +35 -631
- data/performance/cache_runner.rb +123 -0
- data/performance/cpu.rb +28 -0
- data/performance/externals.rb +45 -0
- data/performance/profile.rb +26 -0
- data/test/attribute_cache_test.rb +3 -3
- data/test/fetch_multi_test.rb +13 -39
- data/test/fetch_multi_with_batched_associations_test.rb +236 -0
- data/test/fetch_test.rb +1 -1
- data/test/helpers/active_record_objects.rb +43 -0
- data/test/helpers/cache.rb +3 -12
- data/test/helpers/database_connection.rb +2 -1
- data/test/index_cache_test.rb +7 -0
- data/test/memoized_cache_proxy_test.rb +46 -1
- data/test/normalized_has_many_test.rb +13 -0
- data/test/recursive_denormalized_has_many_test.rb +17 -2
- data/test/save_test.rb +2 -2
- data/test/schema_change_test.rb +8 -28
- data/test/test_helper.rb +49 -43
- metadata +76 -76
- data/lib/memoized_cache_proxy.rb +0 -71
data/lib/memoized_cache_proxy.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
require 'monitor'
|
2
|
-
|
3
|
-
module IdentityCache
|
4
|
-
class MemoizedCacheProxy
|
5
|
-
attr_writer :memcache
|
6
|
-
|
7
|
-
def initialize(memcache = nil)
|
8
|
-
@memcache = memcache || Rails.cache
|
9
|
-
@key_value_maps = Hash.new {|h, k| h[k] = {} }
|
10
|
-
end
|
11
|
-
|
12
|
-
def memoized_key_values
|
13
|
-
@key_value_maps[Thread.current.object_id]
|
14
|
-
end
|
15
|
-
|
16
|
-
def with_memoization(&block)
|
17
|
-
Thread.current[:memoizing_idc] = true
|
18
|
-
yield
|
19
|
-
ensure
|
20
|
-
clear_memoization
|
21
|
-
Thread.current[:memoizing_idc] = false
|
22
|
-
end
|
23
|
-
|
24
|
-
def write(key, value)
|
25
|
-
memoized_key_values[key] = value if memoizing?
|
26
|
-
@memcache.write(key, value)
|
27
|
-
end
|
28
|
-
|
29
|
-
def read(key)
|
30
|
-
if memoizing?
|
31
|
-
memoized_key_values[key] ||= @memcache.read(key)
|
32
|
-
else
|
33
|
-
@memcache.read(key)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def delete(key)
|
38
|
-
memoized_key_values.delete(key) if memoizing?
|
39
|
-
@memcache.delete(key)
|
40
|
-
end
|
41
|
-
|
42
|
-
def read_multi(*keys)
|
43
|
-
hash = {}
|
44
|
-
|
45
|
-
if memoizing?
|
46
|
-
keys.reduce({}) do |hash, key|
|
47
|
-
hash[key] = memoized_key_values[key] if memoized_key_values[key].present?
|
48
|
-
hash
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
missing_keys = keys - hash.keys
|
53
|
-
hash.merge(@memcache.read_multi(*missing_keys))
|
54
|
-
end
|
55
|
-
|
56
|
-
def clear
|
57
|
-
clear_memoization
|
58
|
-
@memcache.clear
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def clear_memoization
|
64
|
-
@key_value_maps.delete(Thread.current.object_id)
|
65
|
-
end
|
66
|
-
|
67
|
-
def memoizing?
|
68
|
-
Thread.current[:memoizing_idc]
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|