Class: CachedResource::Config
- Inherits:
-
Object
- Object
- CachedResource::Config
- 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
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cache_enabled ⇒ Object
Returns the value of attribute cache_enabled.
-
#cache_time_to_live ⇒ Object
Returns the value of attribute cache_time_to_live.
-
#logger ⇒ Object
Returns the value of attribute logger.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
initialize the config with caching enabled and a default cache expiry of 7 days.
Constructor Details
#initialize ⇒ Config
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
#cache ⇒ Object
Returns the value of attribute cache.
13 14 15 |
# File 'lib/cached_resource/config.rb', line 13 def cache @cache end |
#cache_enabled ⇒ Object
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_live ⇒ Object
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 |
#logger ⇒ Object
Returns the value of attribute logger.
13 14 15 |
# File 'lib/cached_resource/config.rb', line 13 def logger @logger end |