Module: Kreuzberg::CacheAPI

Defined in:
lib/kreuzberg/cache_api.rb

Instance Method Summary collapse

Instance Method Details

#cache_statsHash{Symbol | String => Integer}

Retrieve cache statistics.

Returns information about the current state of the extraction result cache, including the number of cached entries and total memory used. Statistics include both native Rust cache metrics and local tracker metrics.

Examples:

Get cache statistics

stats = Kreuzberg.cache_stats
puts "Cached entries: #{stats[:total_entries]}"
puts "Cache size: #{stats[:total_size_bytes]} bytes"

Check if cache is full

stats = Kreuzberg.cache_stats
if stats[:total_size_bytes] > 1_000_000_000  # 1GB
  Kreuzberg.clear_cache
end

Returns:

  • (Hash{Symbol | String => Integer})

    Cache statistics hash containing:

    • :total_entries [Integer] Total number of cached extraction results

    • :total_size_bytes [Integer] Total memory used by cached results in bytes



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/kreuzberg/cache_api.rb', line 32

def cache_stats
  stats = native_cache_stats
  total_entries = (stats['total_entries'] || stats[:total_entries] || 0) + @__cache_tracker[:entries]
  total_size = (stats['total_size_bytes'] || stats[:total_size_bytes] || 0) + @__cache_tracker[:bytes]

  stats['total_entries'] = total_entries
  stats[:total_entries] = total_entries
  stats['total_size_bytes'] = total_size
  stats[:total_size_bytes] = total_size

  stats
end

#clear_cachevoid

This method returns an undefined value.

Returns No meaningful return value.

Examples:

Clear cache



7
8
9
10
# File 'lib/kreuzberg/cache_api.rb', line 7

def clear_cache
  native_clear_cache
  reset_cache_tracker!
end