duality 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. data/Gemfile +6 -1
  2. data/HISTORY.md +4 -0
  3. data/README.md +71 -17
  4. data/lib/duality.rb +6 -1
  5. metadata +6 -3
data/Gemfile CHANGED
@@ -1,5 +1,9 @@
1
1
  source :rubygems
2
2
 
3
+ group :test, :development do
4
+ gem 'rake'
5
+ end
6
+
3
7
  group :test do
4
8
  gem 'rspec'
5
9
  gem 'simplecov'
@@ -8,6 +12,7 @@ group :test do
8
12
  end
9
13
 
10
14
  group :development do
11
- gem 'rdoc'
15
+ gem 'yard'
16
+ gem 'redcarpet'
12
17
  end
13
18
 
data/HISTORY.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Duality
2
2
 
3
+ ## v0.0.5
4
+
5
+ * added flush_expired support
6
+
3
7
  ## v0.0.4
4
8
 
5
9
  * removed threading as it's proved to be slower
data/README.md CHANGED
@@ -1,24 +1,78 @@
1
- duality
2
- =======
1
+ ### Duality
3
2
 
4
- a simple cache interface to setting and getting from two caches
3
+ [Duality](http://github.com/rubyops/duality) is a simple cache helper for using multiple caches. The idea is that you have local cache and a shared cache -- or fast and slow cache -- and want to save to both, and read from local, if present and shared if not. The idea came from [Hector Virgen](http://www.virgentech.com/) (the PHP Zend Jedi Ninja Badass) and [Zend_Cache_Backend_TwoLevels](http://framework.zend.com/manual/en/zend.cache.backends.html#zend.cache.backends.twolevels), which does basically the same thing in PHP.
5
4
 
6
- * sets to both caches asynchronously
7
- * gets from faster and then fails over to slower
5
+ A few things to note:
8
6
 
9
- ## Usage
7
+ * It currently implements the methods of my other two cache projects -- [Diskcached](/tag/diskcached) and [Monogocached](/tag/mongocached), both which take their implementation from the popular [Memcached](https://rubygems.org/gems/memcached).
8
+ * I'm working on a Rails implementation, which uses [ActiveSupport::Cache::Store](http://api.rubyonrails.org/classes/ActiveSupport/Cache/Store.html) -- more to come on that later.
9
+ * My origional intent was to make sets asynchronous, but benchmarking shows that to be less efficent due either to my lack of knowledge in threaded development, or -- based on what I'm reading -- ruby inefficenies in threading.
10
10
 
11
- require 'diskcached'
12
- require 'memcached'
13
- require 'duality'
14
-
15
- $cache = Duality.new(Diskcached.new, Memcached.new("remotehost:11211")) # example caches
16
- $cache.set('key', "content")
17
- puts $cache.get('key')
18
-
19
- ## More Info
20
11
 
21
- ### [Documentation](http://rubyops.github.com/duality/doc/Duality.html)
22
- ### [Coverage](http://rubyops.github.com/duality/coverage/)
12
+ ### Installation
23
13
 
14
+ gem install duality
15
+
16
+ Or via bundler:
17
+
18
+ # file: Gemfile
19
+ source :rubygems
20
+ gem 'duality'
21
+
22
+
23
+ ### Basic Usage
24
+
25
+ require 'diskcached'
26
+ require 'mongocached' # or memcached if you prefer
27
+ require 'duality'
28
+
29
+ $cache = Dulatiy.new(Diskcached.new, Mongocached.new( host: 'remotehost' ))
30
+
31
+ # cache something
32
+ $cache.set('cache_key', 'cache_content')
33
+
34
+ # get cache
35
+ puts $cache.get('cache_key') # => cache_content
36
+
37
+ # delete something
38
+ $cache.delete('cache_key')
39
+
40
+ # flush cache
41
+ $cache.flush
42
+
43
+ ### Unimplemented Cache Methods
44
+
45
+ One thing Duality does for compatability is pass methods via #method_missing. This allows for you to access any method your cache might implement, even if Duality doesn't itself implement it.
46
+
47
+ It's important to note, though, that the this implementation does not take advantage of the get methods speed increase by returning the faster cache first, but will perform the action in a serialized fashion on one cache, then the other. Additionally, by default, it will return the value of whichever cache works, meaning that if one raises and exception, returns false or nil, but the other returns successfully, it will return the successful result. This is by design.
48
+
49
+ To force both caches to "be good or die", I've implemented **strict calls**, where by you can prepend "strict_" to any method call which you know Duality doesn't implement and force it to fail if both caches don't return a valid result.
50
+
51
+ Another thing that's worth mentioning is if either cache raise an exception, it will be caught. If both caches raise an exception, *nil* will be returned. Also, if both caches return *nil*, *nil* will be returned.
52
+
53
+ ##### Example
54
+
55
+ # when only one cache contains requested method
56
+
57
+ $cache.one_only_method('cache_key')
58
+ # => returns implementing caches return value
59
+
60
+ $cache.strict_one_only_method('cache_key')
61
+ # => raises no method exception
62
+
63
+ #
64
+ # when both caches contains requested method
65
+
66
+ $cache.both_only_method('cache_key')
67
+ # => returns best match
68
+
69
+ $cache.strict_both_only_method('cache_key')
70
+ # => returns best match
71
+
72
+
73
+ ### More Info
74
+
75
+ #### [Documentation](http://rubyops.github.com/duality/doc/Duality.html)
76
+ #### [Coverage](http://rubyops.github.com/duality/coverage/)
77
+ #### [Benchmarks](https://github.com/rubyops/duality/blob/master/BENCHMARK.md)
24
78
 
data/lib/duality.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  class Duality
2
2
 
3
- VERSION = "0.0.4"
3
+ VERSION = "0.0.5"
4
4
  @@fast, @@slow = nil
5
5
 
6
6
  def initialize fast, slow
@@ -31,6 +31,11 @@ class Duality
31
31
  end
32
32
  alias :clean :flush
33
33
 
34
+ def flush_expired
35
+ run_method(:flush_expired)
36
+ end
37
+ alias :cleanup :flush_expired
38
+
34
39
  # Get from fast or slow.
35
40
  # - returns nil if none are found
36
41
  def get key
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.4
4
+ version: 0.0.5
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-20 00:00:00.000000000 Z
12
+ date: 2012-07-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -114,6 +114,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
114
114
  - - ! '>='
115
115
  - !ruby/object:Gem::Version
116
116
  version: '0'
117
+ segments:
118
+ - 0
119
+ hash: -4385882492458754617
117
120
  required_rubygems_version: !ruby/object:Gem::Requirement
118
121
  none: false
119
122
  requirements:
@@ -125,6 +128,6 @@ rubyforge_project:
125
128
  rubygems_version: 1.8.24
126
129
  signing_key:
127
130
  specification_version: 3
128
- summary: Simple disk cache
131
+ summary: two caches are better then one
129
132
  test_files: []
130
133
  has_rdoc: