Class: AnyCache::Adapters::ActiveSupportNaiveStore Private

Inherits:
Delegator show all
Defined in:
lib/any_cache/adapters/active_support_naive_store.rb,
lib/any_cache/adapters/active_support_naive_store/expire.rb,
lib/any_cache/adapters/active_support_naive_store/persist.rb,
lib/any_cache/adapters/active_support_naive_store/decrement.rb,
lib/any_cache/adapters/active_support_naive_store/increment.rb,
lib/any_cache/adapters/active_support_naive_store/operation.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.1.0

Defined Under Namespace

Classes: Decrement, Expire, Increment, Operation, Persist

Instance Attribute Summary

Attributes inherited from Basic

#driver

Instance Method Summary collapse

Methods inherited from Delegator

supported_driver?

Methods inherited from Basic

supported_driver?

Methods included from Dumper::InterfaceAccessMixin

#detransform_pairset, #detransform_value, #transform_pairset, #transform_value

Constructor Details

#initialize(driver) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • driver (Object)

Since:

  • 0.1.0



18
19
20
21
22
23
24
25
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 18

def initialize(driver)
  super
  @lock = Concurrent::ReentrantReadWriteLock.new
  @incr_operation = self.class::Increment.new(driver)
  @decr_operation = self.class::Decrement.new(driver)
  @expr_operation = self.class::Expire.new(driver)
  @pers_operation = self.class::Persist.new(driver)
end

Instance Method Details

#cleanup(**options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • options (Hash)

Since:

  • 0.4.0



85
86
87
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 85

def cleanup(**options)
  lock.with_write_lock { super }
end

#clear(**options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • options (Hash)

Since:

  • 0.1.0



76
77
78
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 76

def clear(**options)
  lock.with_write_lock { super }
end

#decrement(key, amount = self.class::Decrement::DEFAULT_AMOUNT, **options) ⇒ Integer, Float

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)
  • amount (Integer, Float) (defaults to: self.class::Decrement::DEFAULT_AMOUNT)
  • expires_in (Hash)

    a customizable set of options

Returns:

  • (Integer, Float)

Since:

  • 0.1.0



181
182
183
184
185
186
187
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 181

def decrement(key, amount = self.class::Decrement::DEFAULT_AMOUNT, **options)
  lock.with_write_lock do
    expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL)

    decr_operation.call(key, amount, expires_in: expires_in)
  end
end

#delete(key, **options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • key (String)
  • options (Hash)

Since:

  • 0.1.0



57
58
59
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 57

def delete(key, **options)
  lock.with_write_lock { super }
end

#delete_matched(pattern, **options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • pattern (String, Regexp)
  • options (Hash)

Since:

  • 0.3.0



67
68
69
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 67

def delete_matched(pattern, **options)
  lock.with_write_lock { super }
end

#exist?(key, **options) ⇒ Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)
  • options (Hash)

Returns:

  • (Boolean)

Since:

  • 0.2.0



215
216
217
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 215

def exist?(key, **options)
  lock.with_read_lock { super }
end

#expire(key, expires_in: self.class::Operation::DEAD_TTL) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • key (String)
  • expires_in (Hash) (defaults to: self.class::Operation::DEAD_TTL)

    a customizable set of options

Options Hash (expires_in:):

  • (NilClass, Integer)

Since:

  • 0.1.0



195
196
197
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 195

def expire(key, expires_in: self.class::Operation::DEAD_TTL)
  lock.with_write_lock { expr_operation.call(key, expires_in: expires_in) }
end

#fetch(key, **options, &fallback) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)
  • fallback (Proc)
  • expires_in (Hash)

    a customizable set of options

  • force (Hash)

    a customizable set of options

Returns:

  • (Object)

Since:

  • 0.2.0



126
127
128
129
130
131
132
133
134
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 126

def fetch(key, **options, &fallback)
  lock.with_write_lock do
    force_rewrite = options.fetch(:force, false)
    force_rewrite = force_rewrite.call(key) if force_rewrite.respond_to?(:call)
    expires_in    = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL)

    super(key, force: force_rewrite, expires_in: expires_in, &fallback)
  end
end

#fetch_multi(*keys, **options, &fallback) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • keys (Array<String>)
  • fallback (Proc)
  • force (Hash)

    a customizable set of options

  • expires_in (Hash)

    a customizable set of options

Returns:

  • (Hash)

Since:

  • 0.3.0



144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 144

def fetch_multi(*keys, **options, &fallback)
  lock.with_write_lock do
    force_rewrite = options.fetch(:force, false)
    expires_in    = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL)

    # NOTE:
    #   use own #fetch_multi implementation cuz original #fetch_multi
    #   does not support :force option
    keys.each_with_object({}) do |key, dataset|
      force = force_rewrite.respond_to?(:call) ? force_rewrite.call(key) : force_rewrite
      dataset[key] = driver.fetch(key, force: force, expires_in: expires_in, &fallback)
    end
  end
end

#increment(key, amount = self.class::Increment::DEFAULT_AMOUNT, **options) ⇒ Integer, Float

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)
  • amount (Integer, Float) (defaults to: self.class::Increment::DEFAULT_AMOUNT)
  • expires_in (Hash)

    a customizable set of options

Returns:

  • (Integer, Float)

Since:

  • 0.1.0



166
167
168
169
170
171
172
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 166

def increment(key, amount = self.class::Increment::DEFAULT_AMOUNT, **options)
  lock.with_write_lock do
    expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL)

    incr_operation.call(key, amount, expires_in: expires_in)
  end
end

#persist(key, **options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • key (String)
  • options (Hash)

Since:

  • 0.1.0



205
206
207
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 205

def persist(key, **options)
  lock.with_write_lock { pers_operation.call(key) }
end

#read(key, **options) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • key (String)
  • options (Hash)

Returns:

  • (Object)

Since:

  • 0.1.0



33
34
35
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 33

def read(key, **options)
  lock.with_read_lock { super }
end

#read_multi(*keys, **options) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • keys (Array<String>)
  • options (Hash)

Returns:

  • (Hash)

Since:

  • 0.3.0



43
44
45
46
47
48
49
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 43

def read_multi(*keys, **options)
  lock.with_read_lock do
    super.tap do |res|
      res.merge!(Hash[(keys - res.keys).zip(Operation::READ_MULTI_EMPTY_KEYS_SET)])
    end
  end
end

#write(key, value, **options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • key (String)
  • value (Object)
  • options (Hash)

Since:

  • 0.1.0



96
97
98
99
100
101
102
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 96

def write(key, value, **options)
  lock.with_write_lock do
    expires_in = options.fetch(:expires_in, self.class::Operation::NO_EXPIRATION_TTL)

    super(key, value, expires_in: expires_in)
  end
end

#write_multi(entries, **options) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

  • entries (Hash)
  • options (Hash)

Since:

  • 0.3.0



110
111
112
113
114
115
116
# File 'lib/any_cache/adapters/active_support_naive_store.rb', line 110

def write_multi(entries, **options)
  lock.with_write_lock do
    expires_in = self.class::Operation::NO_EXPIRATION_TTL

    super(entries, expires_in: expires_in)
  end
end