Module: SolidCache::Store::Api

Included in:
SolidCache::Store
Defined in:
lib/solid_cache/store/api.rb

Constant Summary collapse

DEFAULT_MAX_KEY_BYTESIZE =
1024
SQL_WILDCARD_CHARS =
[ "_", "%" ]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#max_key_bytesizeObject (readonly)

Returns the value of attribute max_key_bytesize.



7
8
9
# File 'lib/solid_cache/store/api.rb', line 7

def max_key_bytesize
  @max_key_bytesize
end

Instance Method Details

#cleanup(options = nil) ⇒ Object

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/solid_cache/store/api.rb', line 43

def cleanup(options = nil)
  raise NotImplementedError.new("#{self.class.name} does not support cleanup")
end

#clear(options = nil) ⇒ Object



47
48
49
# File 'lib/solid_cache/store/api.rb', line 47

def clear(options = nil)
  entry_clear
end

#decrement(name, amount = 1, options = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/solid_cache/store/api.rb', line 36

def decrement(name, amount = 1, options = nil)
  options = merged_options(options)
  key = normalize_key(name, options)

  entry_decrement(key, amount)
end

#delete_matched(matcher, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/solid_cache/store/api.rb', line 15

def delete_matched(matcher, options = {})
  instrument :delete_matched, matcher do
    raise ArgumentError, "Only strings are supported: #{matcher.inspect}" unless String === matcher
    raise ArgumentError, "Strings cannot start with wildcards" if SQL_WILDCARD_CHARS.include?(matcher[0])

    options ||= {}
    batch_size = options.fetch(:batch_size, 1000)

    matcher = namespace_key(matcher, options)

    entry_delete_matched(matcher, batch_size)
  end
end

#increment(name, amount = 1, options = nil) ⇒ Object



29
30
31
32
33
34
# File 'lib/solid_cache/store/api.rb', line 29

def increment(name, amount = 1, options = nil)
  options = merged_options(options)
  key = normalize_key(name, options)

  entry_increment(key, amount)
end

#initialize(options = {}) ⇒ Object



9
10
11
12
13
# File 'lib/solid_cache/store/api.rb', line 9

def initialize(options = {})
  super(options)

  @max_key_bytesize = options.fetch(:max_key_bytesize, DEFAULT_MAX_KEY_BYTESIZE)
end