Class: SocialAvatarProxy::Configuration::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/social_avatar_proxy/configuration/cache.rb

Direct Known Subclasses

FileCache, Memcache

Instance Method Summary collapse

Instance Method Details

#configure(&block) ⇒ Object



26
27
28
29
# File 'lib/social_avatar_proxy/configuration/cache.rb', line 26

def configure(&block)
  enable
  instance_eval(&block)
end

#disabled?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/social_avatar_proxy/configuration/cache.rb', line 31

def disabled?
  !enabled?
end

#enabled?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/social_avatar_proxy/configuration/cache.rb', line 35

def enabled?
  !!@enabled
end

#fetch(options = {}, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/social_avatar_proxy/configuration/cache.rb', line 12

def fetch(options = {}, &block)
  # if the cache is enabled attempt read
  file = attempt_read(options)
  # if read fails yield the block
  # if the cache is enabled attempt write
  # return the block result
  unless file
    file = block.yield
    attempt_write(file, options) if file
  end
  # return the file
  file
end

#read(options = {}) ⇒ Object



4
5
6
# File 'lib/social_avatar_proxy/configuration/cache.rb', line 4

def read(options = {})
  false
end

#write(file, options = {}) ⇒ Object



8
9
10
# File 'lib/social_avatar_proxy/configuration/cache.rb', line 8

def write(file, options = {})
  file
end