Class: DoubleWriteCacheStores::Client
- Inherits:
-
Object
- Object
- DoubleWriteCacheStores::Client
- Defined in:
- lib/double_write_cache_stores/client.rb
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #delete(key) ⇒ Object
- #flush ⇒ Object
- #get(key) ⇒ Object
- #get_cas(key) ⇒ Object
-
#initialize(read_and_write_store_servers, write_only_store_servers = nil) ⇒ Client
constructor
A new instance of Client.
- #read(key) ⇒ Object
- #set(key, value, options = nil) ⇒ Object
- #set_cas(key, value, cas, options = nil) ⇒ Object
- #touch(key) ⇒ Object
- #write(key, value, options = nil) ⇒ Object
Constructor Details
#initialize(read_and_write_store_servers, write_only_store_servers = nil) ⇒ Client
Returns a new instance of Client.
2 3 4 5 6 7 8 9 10 |
# File 'lib/double_write_cache_stores/client.rb', line 2 def initialize(read_and_write_store_servers, write_only_store_servers = nil) @read_and_write_store = read_and_write_store_servers if write_only_store_servers if read_and_write_store_servers.class != write_only_store_servers.class fail "different cache store instance. #{read_and_write_store_servers.class} != #{write_only_store_servers.class}" end @write_only_store = write_only_store_servers end end |
Instance Method Details
#[](key) ⇒ Object
12 13 14 |
# File 'lib/double_write_cache_stores/client.rb', line 12 def [](key) get key end |
#[]=(key, value) ⇒ Object
43 44 45 |
# File 'lib/double_write_cache_stores/client.rb', line 43 def []=(key, value) set key, value end |
#delete(key) ⇒ Object
38 39 40 41 |
# File 'lib/double_write_cache_stores/client.rb', line 38 def delete(key) @read_and_write_store.delete key @write_only_store.delete key if @write_only_store end |
#flush ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/double_write_cache_stores/client.rb', line 65 def flush if flush_cache_store || flush_cache_store(:clear) true else false end end |
#get(key) ⇒ Object
16 17 18 |
# File 'lib/double_write_cache_stores/client.rb', line 16 def get(key) get_or_read_method_call key end |
#get_cas(key) ⇒ Object
20 21 22 |
# File 'lib/double_write_cache_stores/client.rb', line 20 def get_cas(key) @read_and_write_store.get_cas key end |
#read(key) ⇒ Object
34 35 36 |
# File 'lib/double_write_cache_stores/client.rb', line 34 def read(key) get_or_read_method_call key end |
#set(key, value, options = nil) ⇒ Object
47 48 49 |
# File 'lib/double_write_cache_stores/client.rb', line 47 def set(key, value, = nil) write_cache_store key, value, end |
#set_cas(key, value, cas, options = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/double_write_cache_stores/client.rb', line 24 def set_cas(key, value, cas, = nil) cas_unique = @read_and_write_store.set_cas key, value, cas, if @write_only_store && cas_unique set_or_write_method_call @write_only_store, key, value, end cas_unique end |
#touch(key) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'lib/double_write_cache_stores/client.rb', line 55 def touch(key) result = false read_and_write_backend = @read_and_write_store.instance_variable_get('@backend') || @read_and_write_store.instance_variable_get('@data') if read_and_write_backend && read_and_write_backend.respond_to?(:touch) result = read_and_write_backend.touch key write_only_store_touch key end result end |
#write(key, value, options = nil) ⇒ Object
51 52 53 |
# File 'lib/double_write_cache_stores/client.rb', line 51 def write(key, value, = nil) write_cache_store key, value, end |