Class: Fontist::Cache::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/cache/manager.rb

Overview

Central cache manager for font index caching operations

Class Method Summary collapse

Class Method Details

.cache_dirObject

Cache directory is determined lazily to avoid initialization issues



10
11
12
# File 'lib/fontist/cache/manager.rb', line 10

def cache_dir
  @cache_dir ||= Fontist.root_path.join("cache")
end

.clear(namespace: nil) ⇒ Object



27
28
29
30
31
# File 'lib/fontist/cache/manager.rb', line 27

def clear(namespace: nil)
  return clear_all unless namespace

  store(namespace).clear
end

.delete(key, namespace: nil) ⇒ Object



23
24
25
# File 'lib/fontist/cache/manager.rb', line 23

def delete(key, namespace: nil)
  store(namespace).delete(key)
end

.get(key, namespace: nil) ⇒ Object

Public API for cache operations



15
16
17
# File 'lib/fontist/cache/manager.rb', line 15

def get(key, namespace: nil)
  store(namespace).get(key)
end

.get_directory_fonts(directory_path) ⇒ Object

Convenience methods for directory-level caching



34
35
36
# File 'lib/fontist/cache/manager.rb', line 34

def get_directory_fonts(directory_path)
  get("directory:#{directory_path}", namespace: :indexes)
end

.set(key, value, ttl: nil, namespace: nil) ⇒ Object



19
20
21
# File 'lib/fontist/cache/manager.rb', line 19

def set(key, value, ttl: nil, namespace: nil)
  store(namespace).set(key, value, ttl: ttl)
end

.set_directory_fonts(directory_path, fonts) ⇒ Object



38
39
40
41
# File 'lib/fontist/cache/manager.rb', line 38

def set_directory_fonts(directory_path, fonts)
  set("directory:#{directory_path}", fonts, ttl: 3600,
                                            namespace: :indexes)
end