Class: CachedResource::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/cached_resource/config.rb

Overview

The Config class is a singleton that contains global configuration options for CacheResource

Constant Summary collapse

DEFAULT_CACHE_TIME_TO_LIVE =

set default cache time to live to 1 week

604800
LOGGER_PREFIX =

prefix for log messages

"[cached_resource]"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

initialize the config with caching enabled and a default cache expiry of 7 days. Also initializes the logging and caching mechanisms, setting them to the Rails logger and cache if available. If unavailable, sets them to active support equivalents



20
21
22
23
24
25
26
# File 'lib/cached_resource/config.rb', line 20

def initialize
  @cache_enabled = true
  @cache_time_to_live = DEFAULT_CACHE_TIME_TO_LIVE

  @cache = defined?(Rails.cache)  && Rails.cache || ActiveSupport::Cache::MemoryStore.new
  @logger = defined?(Rails.logger) && Rails.logger || ActiveSupport::BufferedLogger.new(StringIO.new)
end

Instance Attribute Details

#cacheObject

Returns the value of attribute cache.



13
14
15
# File 'lib/cached_resource/config.rb', line 13

def cache
  @cache
end

#cache_enabledObject

Returns the value of attribute cache_enabled.



13
14
15
# File 'lib/cached_resource/config.rb', line 13

def cache_enabled
  @cache_enabled
end

#cache_time_to_liveObject

Returns the value of attribute cache_time_to_live.



13
14
15
# File 'lib/cached_resource/config.rb', line 13

def cache_time_to_live
  @cache_time_to_live
end

#loggerObject

Returns the value of attribute logger.



13
14
15
# File 'lib/cached_resource/config.rb', line 13

def logger
  @logger
end