duality 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/HISTORY.md +8 -0
  2. data/lib/duality.rb +23 -28
  3. metadata +3 -2
data/HISTORY.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Duality
2
2
 
3
+ ## v0.0.4
4
+
5
+ * removed threading as it's proved to be slower
6
+
7
+ ## v0.0.3
8
+
9
+ * updated thread timeout to be more thready
10
+
3
11
  ## v0.0.2
4
12
 
5
13
  * moved from process forking to threading model
data/lib/duality.rb CHANGED
@@ -1,57 +1,33 @@
1
- require 'timeout'
2
1
  class Duality
3
2
 
4
- VERSION = "0.0.3"
5
- #DEFAULT_TIMEOUT=1
3
+ VERSION = "0.0.4"
6
4
  @@fast, @@slow = nil
7
5
 
8
- # Used to set cache connection timeout
9
- # - default is 0.5 seconds
10
- #attr_accessor :timeout
11
-
12
6
  def initialize fast, slow
13
7
  # check params are caches
14
8
  raise NotACache unless fast.respond_to?(:set) && fast.respond_to?(:get)
15
9
  raise NotACache unless slow.respond_to?(:set) && slow.respond_to?(:get)
16
10
  @fast = fast
17
11
  @slow = slow
18
- Thread.abort_on_exception = true
19
12
  end
20
13
 
21
- # Return set timeout or use default.
22
- #def timeout
23
- #@timeout||DEFAULT_TIMEOUT
24
- #end
25
-
26
14
  # Set to fast and slow.
27
15
  # - return true if both succeed
28
16
  # - return false if either fail
29
17
  def set key, value
30
- fast = Thread.new { @fast.set(key, value) }
31
- slow = Thread.new { @slow.set(key, value) }
32
- fast.join(1)
33
- slow.join(1)
34
- (fast.status == false && slow.status == false)
18
+ run_method(:set, key, value)
35
19
  end
36
20
  alias :save :set
37
21
 
38
22
  # Delete from both - async
39
23
  def delete key
40
- fast = Thread.new { @fast.delete(key) }
41
- slow = Thread.new { @slow.delete(key) }
42
- fast.join(1)
43
- slow.join(1)
44
- (fast.status == false && slow.status == false)
24
+ run_method(:delete, key)
45
25
  end
46
26
  alias :remove :delete
47
27
 
48
28
  # Flush caches - async
49
29
  def flush
50
- fast = Thread.new { @fast.flush }
51
- slow = Thread.new { @slow.flush }
52
- fast.join(1)
53
- slow.join(1)
54
- (fast.status == false && slow.status == false)
30
+ run_method(:flush)
55
31
  end
56
32
  alias :clean :flush
57
33
 
@@ -96,6 +72,25 @@ class Duality
96
72
  return fast
97
73
  end
98
74
 
75
+ def run_method meth, *args
76
+ success = true
77
+ begin
78
+ @fast.send(meth, *args)
79
+ rescue Exception
80
+ success = false
81
+ rescue
82
+ success = false
83
+ end
84
+ begin
85
+ @slow.send(meth, *args)
86
+ rescue Exception
87
+ success = false
88
+ rescue
89
+ success = false
90
+ end
91
+ return success
92
+ end
93
+
99
94
  class NotACache < Exception
100
95
  end
101
96
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: duality
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -127,3 +127,4 @@ signing_key:
127
127
  specification_version: 3
128
128
  summary: Simple disk cache
129
129
  test_files: []
130
+ has_rdoc: