Class: Adhoq::Storage::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/adhoq/storage/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cache, prefix = "", expire = 300) ⇒ Cache

Returns a new instance of Cache.



6
7
8
9
10
# File 'lib/adhoq/storage/cache.rb', line 6

def initialize(cache, prefix = "", expire = 300)
  @cache = cache
  @identifier = @prefix = prefix
  @expire = expire
end

Instance Attribute Details

#identifierObject (readonly)

Returns the value of attribute identifier.



4
5
6
# File 'lib/adhoq/storage/cache.rb', line 4

def identifier
  @identifier
end

Instance Method Details

#direct_download?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/adhoq/storage/cache.rb', line 18

def direct_download?
  false
end

#get(identifier) ⇒ Object



22
23
24
# File 'lib/adhoq/storage/cache.rb', line 22

def get(identifier)
  @cache.read(@prefix + identifier)
end

#store(suffix = nil, seed = Time.now, &block) ⇒ Object



12
13
14
15
16
# File 'lib/adhoq/storage/cache.rb', line 12

def store(suffix = nil, seed = Time.now, &block)
  Adhoq::Storage.with_new_identifier(suffix, seed) do |identifier|
    @cache.write(@prefix + identifier, yield.read, expires_in: @expire)
  end
end