Class: Coradoc::Configurable::CacheConfig

Inherits:
ConfigSection show all
Defined in:
lib/coradoc/configurable.rb

Overview

Cache configuration section

Instance Attribute Summary collapse

Attributes inherited from ConfigSection

#options

Instance Method Summary collapse

Methods inherited from ConfigSection

#[], #[]=, #after_initialize, #merge!, symbolize_keys, #to_h

Constructor Details

#initialize(options = {}) ⇒ CacheConfig

Returns a new instance of CacheConfig.



124
125
126
127
128
129
130
131
# File 'lib/coradoc/configurable.rb', line 124

def initialize(options = {})
  super
  @enabled = @options.fetch(:enabled, true)
  @max_size = @options.fetch(:max_size, 1000)
  @ttl = @options.fetch(:ttl, 0)
  @backend = @options.fetch(:backend, :memory)
  @cache_dir = @options.fetch(:cache_dir, nil)
end

Instance Attribute Details

#backendSymbol

Returns Cache storage backend (:memory, :file, :redis).

Returns:

  • (Symbol)

    Cache storage backend (:memory, :file, :redis)



119
120
121
# File 'lib/coradoc/configurable.rb', line 119

def backend
  @backend
end

#cache_dirString?

Returns Cache directory for file backend.

Returns:

  • (String, nil)

    Cache directory for file backend



122
123
124
# File 'lib/coradoc/configurable.rb', line 122

def cache_dir
  @cache_dir
end

#enabledBoolean

Returns Whether caching is enabled.

Returns:

  • (Boolean)

    Whether caching is enabled



110
111
112
# File 'lib/coradoc/configurable.rb', line 110

def enabled
  @enabled
end

#max_sizeInteger

Returns Maximum cache size (number of entries).

Returns:

  • (Integer)

    Maximum cache size (number of entries)



113
114
115
# File 'lib/coradoc/configurable.rb', line 113

def max_size
  @max_size
end

#ttlInteger

Returns Cache TTL in seconds (0 = no expiry).

Returns:

  • (Integer)

    Cache TTL in seconds (0 = no expiry)



116
117
118
# File 'lib/coradoc/configurable.rb', line 116

def ttl
  @ttl
end