Class: SpecForge::Documentation::Builder::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/spec_forge/documentation/builder/cache.rb

Overview

Manages caching of endpoint data to avoid re-running blueprints

The Cache stores extracted endpoint data and tracks blueprint file modification times. When blueprints haven't changed, cached data can be reused to speed up documentation generation.

Cache files are stored in the OpenAPI generated directory under a .cache subdirectory.

Examples:

Using the cache

cache = Cache.new
if cache.valid?
  endpoints = cache.read
else
  endpoints = extract_from_blueprints
  cache.create(endpoints)
end

Instance Method Summary collapse

Constructor Details

#initializeCache

Creates a new cache manager

Sets up file paths for endpoint and blueprint caches in the OpenAPI generated directory structure.



34
35
36
37
# File 'lib/spec_forge/documentation/builder/cache.rb', line 34

def initialize
  @endpoint_cache = SpecForge.openapi_path.join("generated", ".cache", "endpoints.yml")
  @blueprint_cache = SpecForge.openapi_path.join("generated", ".cache", "blueprints.yml")
end

Instance Method Details

#create(endpoints) ⇒ void

This method returns an undefined value.

Creates a cache entry with endpoint data and blueprint file metadata

Writes both the endpoint data and current blueprint file modification times to enable cache invalidation when blueprints change.

Parameters:

  • endpoints (Array<Hash>)

    Endpoint data to cache



62
63
64
65
# File 'lib/spec_forge/documentation/builder/cache.rb', line 62

def create(endpoints)
  write_blueprint_cache
  write(endpoints)
end

#readArray<Hash>

Reads cached endpoint data from disk

Returns:

  • (Array<Hash>)

    Previously cached endpoint data

Raises:

  • (StandardError)

    If cache file is missing or corrupted



85
86
87
# File 'lib/spec_forge/documentation/builder/cache.rb', line 85

def read
  read_from_file(@endpoint_cache)
end

#valid?Boolean

Checks if the cache is valid and can be used

Determines cache validity by checking if endpoint cache exists and whether any blueprint files have been modified since the cache was created.

Returns:

  • (Boolean)

    true if cache is valid and can be used



48
49
50
# File 'lib/spec_forge/documentation/builder/cache.rb', line 48

def valid?
  endpoint_cache? && !blueprints_updated?
end

#write(endpoints) ⇒ void

This method returns an undefined value.

Writes endpoint data to the cache file

Parameters:

  • endpoints (Array<Hash>)

    Endpoint data to write



74
75
76
# File 'lib/spec_forge/documentation/builder/cache.rb', line 74

def write(endpoints)
  write_to_file(endpoints, @endpoint_cache)
end