Class: Miteru::Cache

Inherits:
Service show all
Defined in:
lib/miteru/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Service

#call, call, #result, result

Constructor Details

#initialize(url) ⇒ Cache

Returns a new instance of Cache.

Parameters:

  • url (String)


11
12
13
14
# File 'lib/miteru/cache.rb', line 11

def initialize(url)
  super()
  @url = url
end

Instance Attribute Details

#urlString (readonly)

Returns:

  • (String)


6
7
8
# File 'lib/miteru/cache.rb', line 6

def url
  @url
end

Instance Method Details

#cached?(key) ⇒ Boolean

Parameters:

  • key (String)

Returns:

  • (Boolean)


30
31
32
33
34
# File 'lib/miteru/cache.rb', line 30

def cached?(key)
  value = redis.exists?("#{cache_prefix}:#{key}")
  logger.info("Cache:#{key} found.") if verbose?
  value
end

#set(key, value, ex:) ⇒ Object

Parameters:

  • key (String)
  • value (String)
  • ex (Integer. nil)


21
22
23
24
25
# File 'lib/miteru/cache.rb', line 21

def set(key, value, ex:)
  value = redis.set("#{cache_prefix}:#{key}", value, ex:)
  logger.info("Cache:#{key} is set.") if verbose?
  value
end