Class: SpecForge::Documentation::Builder::Cache
- Inherits:
-
Object
- Object
- SpecForge::Documentation::Builder::Cache
- 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.
Instance Method Summary collapse
-
#create(endpoints) ⇒ void
Creates a cache entry with endpoint data and blueprint file metadata.
-
#initialize ⇒ Cache
constructor
Creates a new cache manager.
-
#read ⇒ Array<Hash>
Reads cached endpoint data from disk.
-
#valid? ⇒ Boolean
Checks if the cache is valid and can be used.
-
#write(endpoints) ⇒ void
Writes endpoint data to the cache file.
Constructor Details
#initialize ⇒ Cache
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.
62 63 64 65 |
# File 'lib/spec_forge/documentation/builder/cache.rb', line 62 def create(endpoints) write_blueprint_cache write(endpoints) end |
#read ⇒ Array<Hash>
Reads cached endpoint data from disk
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.
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
74 75 76 |
# File 'lib/spec_forge/documentation/builder/cache.rb', line 74 def write(endpoints) write_to_file(endpoints, @endpoint_cache) end |