Class: Dbviewer::Cache::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dbviewer/cache/base.rb

Overview

Base handles caching concerns for the DatabaseManager It provides an abstraction layer for managing caches efficiently

Direct Known Subclasses

InMemory

Instance Method Summary collapse

Constructor Details

#initialize(cache_expiry = 300) ⇒ Base

Initialize the cache manager

Parameters:

  • cache_expiry (Integer) (defaults to: 300)

    Cache expiration time in seconds (default: 300)



8
9
10
11
12
# File 'lib/dbviewer/cache/base.rb', line 8

def initialize(cache_expiry = 300)
  @cache_expiry = cache_expiry
  @unified_cache = {}
  @cache_last_reset = Time.now
end

Instance Method Details

#delete(key) ⇒ Object?

Delete a specific cache entry by key

Parameters:

  • key (String)

    Cache key to delete

Returns:

  • (Object, nil)

    The deleted value or nil if not found

Raises:

  • (NotImplementedError)


27
28
29
# File 'lib/dbviewer/cache/base.rb', line 27

def delete(key)
  raise NotImplementedError, "#{self.class}#delete must be implemented by a subclass"
end

#fetch(key, options = {}) { ... } ⇒ Object

Fetch data from cache or execute block if not found/expired

Parameters:

  • key (String)

    Cache key

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

    Options for the cache entry

Options Hash (options):

  • :expires_in (Integer)

    Custom expiry time in seconds

Yields:

  • Block to execute if cache miss or expired

Returns:

  • (Object)

    Cached value or result of block execution

Raises:

  • (NotImplementedError)


20
21
22
# File 'lib/dbviewer/cache/base.rb', line 20

def fetch(key, options = {}, &block)
  raise NotImplementedError, "#{self.class}#fetch must be implemented by a subclass"
end