Module: CardDB::CacheSupport

Defined in:
lib/carddb/cache.rb

Overview

Cache wrapper that provides a unified interface for caching. Supports any cache that responds to read/write (like Rails.cache).

Examples:

With built-in memory cache

CardDB.configure do |config|
  config.cache = CardDB::MemoryCache.new
  config.cache_ttl = 300  # 5 minutes
end

With Rails.cache

CardDB.configure do |config|
  config.cache = Rails.cache
  config.cache_ttl = 300
end

Disabling cache for a specific call

CardDB.games.fetch(id, cache: false)

Class Method Summary collapse

Class Method Details

.cache_key(resource, method, params) ⇒ String

Generate a cache key for a query.

Parameters:

  • resource (String)

    Resource type (publishers, games, etc.)

  • method (String)

    Method name (fetch, get, search, etc.)

  • params (Hash)

    Query parameters

Returns:

  • (String)

    The cache key



115
116
117
118
# File 'lib/carddb/cache.rb', line 115

def self.cache_key(resource, method, params)
  sorted_params = params.sort.map { |k, v| "#{k}=#{v}" }.join('&')
  "carddb:#{resource}:#{method}:#{sorted_params}"
end