Module: Woods::Console::Adapters::CacheAdapter

Defined in:
lib/woods/console/adapters/cache_adapter.rb

Overview

Cache adapter that auto-detects the active cache store.

Supports Redis, Solid Cache, memory, and file cache stores. Detection checks Rails.cache class name first, then falls back to checking for SolidCache constant.

Examples:

CacheAdapter.detect  # => :redis
CacheAdapter.stats   # => { tool: 'cache_stats', params: {} }

Constant Summary collapse

STORE_PATTERNS =
{
  'RedisCacheStore' => :redis,
  'MemoryStore' => :memory,
  'FileStore' => :file
}.freeze

Class Method Summary collapse

Class Method Details

.detectSymbol

Detect the active cache store backend.

Returns:

  • (Symbol)

    One of :redis, :solid_cache, :memory, :file, :unknown



28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/woods/console/adapters/cache_adapter.rb', line 28

def detect
  if defined?(::Rails) && ::Rails.respond_to?(:cache) && ::Rails.cache
    class_name = ::Rails.cache.class.name.to_s
    STORE_PATTERNS.each do |pattern, backend|
      return backend if class_name.include?(pattern)
    end
  end

  return :solid_cache if defined?(::SolidCache)

  :unknown
end

.infoHash

Get cache store info (backend type, configuration).

Returns:

  • (Hash)

    Bridge request



52
53
54
# File 'lib/woods/console/adapters/cache_adapter.rb', line 52

def info
  { tool: 'cache_info', params: {} }
end

.stats(namespace: nil) ⇒ Hash

Get cache store statistics.

Parameters:

  • namespace (String, nil) (defaults to: nil)

    Cache namespace filter

Returns:

  • (Hash)

    Bridge request



45
46
47
# File 'lib/woods/console/adapters/cache_adapter.rb', line 45

def stats(namespace: nil)
  { tool: 'cache_stats', params: { namespace: namespace }.compact }
end