class CacheBuilder

Public Class Methods

new(cache) click to toggle source

@param [Cache] cache Initializes with the type of Cache to be used

# File lib/libcache/cache_builder.rb, line 6
def initialize(cache)
  @cache = cache.new
end
with(cache) click to toggle source

@param [Cache] cache Sets the type of Cache to be used

# File lib/libcache/cache_builder.rb, line 11
def self.with(cache)
  return self.new(cache)
end

Public Instance Methods

build() click to toggle source

Returns the newly created cache

# File lib/libcache/cache_builder.rb, line 48
def build
  @cache.create_store
  return @cache.dup
end
set_expiry(time) click to toggle source

@param [String] time The time value after which an object should expire in the cache. Can be written as '2s' for two seconds, for example. For more info see: github.com/jmettraux/rufus-scheduler/blob/two/README.rdoc#the-time-strings-understood-by-rufus-scheduler

# File lib/libcache/cache_builder.rb, line 23
def set_expiry(time)
  @cache.expiry_time = time
  return self
end
set_max(max_size) click to toggle source

Sets the optional max size of a cache @param [Integer] max_size The max size of the cache

# File lib/libcache/cache_builder.rb, line 37
def set_max(max_size)
  @cache.max_size = max_size
  return self
end
set_post_get(proc) click to toggle source
# File lib/libcache/cache_builder.rb, line 42
def set_post_get(proc)
  @cache.post_get = proc
  return self
end
set_refresh(proc) click to toggle source

Sets the refresh method required for recalling new objects after expiration @param [Proc] proc The refresh method as a Proc object

# File lib/libcache/cache_builder.rb, line 30
def set_refresh(proc)
  @cache.refresh = proc
  return self
end
set_store(path) click to toggle source

Sets the required file path for the FileCache @param [String] path The path of the directory where cached files should be stored

# File lib/libcache/cache_builder.rb, line 17
def set_store(path)
  @cache.store = path
  return self
end