Method: Readthis::Cache#initialize

Defined in:
lib/readthis/cache.rb

#initialize(options = {}) ⇒ Cache

Creates a new Readthis::Cache object with the given options.

Examples:

Create a new cache instance


Readthis::Cache.new(namespace: 'cache',
                    redis: { url: 'redis://localhost:6379/0' })

Create a compressed cache instance


Readthis::Cache.new(compress: true, compression_threshold: 2048)

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :redis (Hash)

    Options that will be passed to the redis connection

  • :compress (Boolean) — default: false

    Enable or disable automatic compression

  • :compression_threshold (Number) — default: 8k

    Minimum string size for compression

  • :expires_in (Number)

    The number of seconds until an entry expires

  • :refresh (Boolean) — default: false

    Automatically refresh key expiration

  • :retain_nils (Boolean) — default: false

    Whether nil values should be included in read_multi output

  • :marshal (Module) — default: Marshal

    Module that responds to ‘dump` and `load`

  • :namespace (String)

    Prefix used to namespace entries

  • :pool_size (Number) — default: 5

    The number of threads in the pool

  • :pool_timeout (Number) — default: 5

    How long before a thread times out



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/readthis/cache.rb', line 50

def initialize(options = {})
  @options = options

  @entity = Readthis::Entity.new(
    marshal: options.fetch(:marshal, Marshal),
    compress: options.fetch(:compress, false),
    threshold: options.fetch(:compression_threshold, 1024)
  )

  @pool = ConnectionPool.new(pool_options(options)) do
    Redis.new(options.fetch(:redis, {}))
  end

  @scripts = Readthis::Scripts.new
end