lock_and_cache 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a51c74453543a2aea1c7a2d38029ed0ca28b19ef
4
- data.tar.gz: 279b3e00a6356f9745163de77d4583e7dda4d90a
3
+ metadata.gz: 05cf8fb6492276dbdd927c7b40877a3115dd4798
4
+ data.tar.gz: 9d522afcc3bbed01ce5876f0465f2cbe655b96bb
5
5
  SHA512:
6
- metadata.gz: db2cc229fd44e3e9432eb4233c23c02625066d5228aeb087e739922004a724627f7b85a4ceb3b54d89a6f6afc4963c17b57712cdf5d4ada077786107e21b625f
7
- data.tar.gz: 396bcc439d0c3ff5bce552115fb69c858c70bcd921518ff7dfd6a770388f50ba6c2b22681273bd203d45afc82fd45a37b5bb187e51304082614b42d3d5d63f30
6
+ metadata.gz: 47ff5574928c53bc0750202ea7808a6565f01e5089928469b4f99aff596ced3f63356100ec85b7d32cdbb6a0872ab90819d28e382b9587d0df118fb8271c5a1b
7
+ data.tar.gz: dc3be7f40572214c213a6928e24cfb84c2c0734b2c3af4238eb569bc625f8aabc0d642cc115ae772c355e190ad12adb0508e69ab85999074d3c42eb9b5bceb8a
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.1.1 / 2015-02-04
2
+
3
+ * Enhancements
4
+
5
+ * Clear individual cached things with #lock_and_cache_clear
6
+
1
7
  0.1.0 / 2015-01-22
2
8
 
3
9
  * Breaking changes
@@ -20,11 +20,11 @@ module LockAndCache
20
20
 
21
21
  class Key
22
22
  attr_reader :obj
23
- attr_reader :kaller
23
+ attr_reader :method_id
24
24
 
25
- def initialize(obj, kaller, parts)
25
+ def initialize(obj, method_id, parts)
26
26
  @obj = obj
27
- @kaller = kaller
27
+ @method_id = method_id
28
28
  @_parts = parts
29
29
  end
30
30
 
@@ -47,23 +47,26 @@ module LockAndCache
47
47
  end
48
48
  end
49
49
 
50
- def method_id
51
- @method_id ||= begin
52
- kaller[0] =~ /in `(\w+)'/
53
- $1 or raise "couldn't get method_id from #{kaller[0]}"
54
- end
55
- end
56
-
57
50
  def obj_class_name
58
51
  @obj_class_name ||= (obj.class == ::Class) ? obj.name : obj.class.name
59
52
  end
60
53
 
61
54
  end
62
55
 
56
+ def lock_and_cache_clear(method_id, *key_parts)
57
+ debug = (ENV['LOCK_AND_CACHE_DEBUG'] == 'true')
58
+ key = LockAndCache::Key.new self, method_id, key_parts
59
+ Thread.exclusive { $stderr.puts "[lock_and_cache] clear #{key.debug}" } if debug
60
+ digest = key.digest
61
+ LockAndCache.storage.del digest
62
+ end
63
+
63
64
  def lock_and_cache(*key_parts)
64
65
  raise "need a block" unless block_given?
65
66
  debug = (ENV['LOCK_AND_CACHE_DEBUG'] == 'true')
66
- key = LockAndCache::Key.new self, caller, key_parts
67
+ caller[0] =~ /in `(\w+)'/
68
+ method_id = $1 or raise "couldn't get method_id from #{kaller[0]}"
69
+ key = LockAndCache::Key.new self, method_id, key_parts
67
70
  digest = key.digest
68
71
  storage = LockAndCache.storage
69
72
  Thread.exclusive { $stderr.puts "[lock_and_cache] A #{key.debug}" } if debug
@@ -1,3 +1,3 @@
1
1
  module LockAndCache
2
- VERSION = '0.1.0'
2
+ VERSION = '0.1.1'
3
3
  end
@@ -69,6 +69,12 @@ describe LockAndCache do
69
69
  expect(foo.click).to eq(1)
70
70
  expect(foo.click).to eq(1)
71
71
  end
72
+
73
+ it "can be cleared" do
74
+ expect(foo.click).to eq(1)
75
+ foo.lock_and_cache_clear :click, foo
76
+ expect(foo.click).to eq(2)
77
+ end
72
78
  end
73
79
 
74
80
  describe "locking" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lock_and_cache
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Seamus Abshere
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-22 00:00:00.000000000 Z
11
+ date: 2015-02-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord