Class: DoubleWriteCacheStores::Client
- Inherits:
-
Object
- Object
- DoubleWriteCacheStores::Client
- Defined in:
- lib/double_write_cache_stores/client.rb
Overview
rubocop:disable Metrics/ClassLength
Instance Attribute Summary collapse
-
#read_and_write_store ⇒ Object
Returns the value of attribute read_and_write_store.
-
#write_only_store ⇒ Object
Returns the value of attribute write_only_store.
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, value) ⇒ Object
- #decrement(key, amount = 1, options = {}) ⇒ Object (also: #decr)
- #delete(key) ⇒ Object
- #fetch(name, options = {}, &_block) ⇒ Object
- #flush ⇒ Object
- #get_cas(key) ⇒ Object
- #get_multi_or_read_multi_method_call(*keys) ⇒ Object (also: #get_multi, #read_multi)
- #get_or_read_method_call(key) ⇒ Object (also: #get, #read)
- #increment(key, amount = 1, options = {}) ⇒ Object (also: #incr)
-
#initialize(read_and_write_store_servers, write_only_store_servers = nil) ⇒ Client
constructor
A new instance of Client.
- #set_cas(key, value, cas = 0, options = nil) ⇒ Object
- #touch(key, ttl = nil) ⇒ Object
- #write_cache_store(key, value, options = nil) ⇒ Object (also: #set, #write)
Constructor Details
#initialize(read_and_write_store_servers, write_only_store_servers = nil) ⇒ Client
Returns a new instance of Client.
5 6 7 8 9 10 11 12 13 |
# File 'lib/double_write_cache_stores/client.rb', line 5 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 raise "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 Attribute Details
#read_and_write_store ⇒ Object
Returns the value of attribute read_and_write_store.
3 4 5 |
# File 'lib/double_write_cache_stores/client.rb', line 3 def read_and_write_store @read_and_write_store end |
#write_only_store ⇒ Object
Returns the value of attribute write_only_store.
3 4 5 |
# File 'lib/double_write_cache_stores/client.rb', line 3 def write_only_store @write_only_store end |
Instance Method Details
#[](key) ⇒ Object
15 16 17 |
# File 'lib/double_write_cache_stores/client.rb', line 15 def [](key) get key end |
#[]=(key, value) ⇒ Object
49 50 51 |
# File 'lib/double_write_cache_stores/client.rb', line 49 def []=(key, value) set key, value end |
#decrement(key, amount = 1, options = {}) ⇒ Object Also known as: decr
88 89 90 |
# File 'lib/double_write_cache_stores/client.rb', line 88 def decrement(key, amount = 1, = {}) decrement_cache_store key, amount, end |
#delete(key) ⇒ Object
43 44 45 46 47 |
# File 'lib/double_write_cache_stores/client.rb', line 43 def delete(key) result = @read_and_write_store.delete key @write_only_store.delete key if @write_only_store result end |
#fetch(name, options = {}, &_block) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/double_write_cache_stores/client.rb', line 67 def fetch(name, = {}, &_block) raise UnSupportException "Unsupported #fetch from client object." unless @read_and_write_store.respond_to?(:fetch) delete name if [:force] if [:race_condition_ttl] fetch_race_condition name, { yield } else unless value = get_or_read_method_call(name) value = yield write_cache_store name, value, end value end end |
#flush ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/double_write_cache_stores/client.rb', line 59 def flush if flush_cache_store || flush_cache_store(:clear) true else false end end |
#get_cas(key) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/double_write_cache_stores/client.rb', line 19 def get_cas(key) if @read_and_write_store.respond_to? :get_cas @read_and_write_store.get_cas key elsif @read_and_write_store.respond_to? :read_cas @read_and_write_store.read_cas key end end |
#get_multi_or_read_multi_method_call(*keys) ⇒ Object Also known as: get_multi, read_multi
110 111 112 113 114 115 116 117 118 |
# File 'lib/double_write_cache_stores/client.rb', line 110 def get_multi_or_read_multi_method_call(*keys) if @read_and_write_store.respond_to? :get_multi @read_and_write_store.get_multi(*keys) elsif @read_and_write_store.respond_to? :read_multi @read_and_write_store.read_multi(*keys) else raise UnSupportException "Unsupported multi keys get or read from client object." end end |
#get_or_read_method_call(key) ⇒ Object Also known as: get, read
100 101 102 103 104 105 106 |
# File 'lib/double_write_cache_stores/client.rb', line 100 def get_or_read_method_call(key) if @read_and_write_store.respond_to? :get @read_and_write_store.get key elsif @read_and_write_store.respond_to? :read @read_and_write_store.read key end end |
#increment(key, amount = 1, options = {}) ⇒ Object Also known as: incr
83 84 85 |
# File 'lib/double_write_cache_stores/client.rb', line 83 def increment(key, amount = 1, = {}) increment_cache_store key, amount, end |
#set_cas(key, value, cas = 0, options = nil) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/double_write_cache_stores/client.rb', line 27 def set_cas(key, value, cas = 0, = nil) cas_unique = if @read_and_write_store.respond_to? :set_cas @read_and_write_store.set_cas key, value, cas, elsif @read_and_write_store.respond_to? :read_cas ||= {} [:cas] = cas @read_and_write_store.write_cas key, value, end if @write_only_store && cas_unique set_or_write_method_call @write_only_store, key, value, end cas_unique end |
#touch(key, ttl = nil) ⇒ Object
53 54 55 56 57 |
# File 'lib/double_write_cache_stores/client.rb', line 53 def touch(key, ttl = nil) result = @read_and_write_store.touch key, ttl @write_only_store.touch key, ttl if @write_only_store result end |
#write_cache_store(key, value, options = nil) ⇒ Object Also known as: set, write
93 94 95 96 |
# File 'lib/double_write_cache_stores/client.rb', line 93 def write_cache_store(key, value, = nil) set_or_write_method_call @read_and_write_store, key, value, set_or_write_method_call @write_only_store, key, value, if @write_only_store end |