| 1 |
// Copyright 2025 Princess B33f Heavy Industries / Dave Shanley |
| 2 |
// SPDX-License-Identifier: MIT |
| 3 |
|
| 4 |
package cache |
| 5 |
|
| 6 |
import ( |
| 7 |
"github.com/pb33f/libopenapi/datamodel/high/base" |
| 8 |
"github.com/santhosh-tekuri/jsonschema/v6" |
| 9 |
"go.yaml.in/yaml/v4" |
| 10 |
) |
| 11 |
|
| 12 |
// SchemaCacheEntry holds a compiled schema and its intermediate representations. |
| 13 |
// This is stored in the cache to avoid re-rendering and re-compiling schemas on each request. |
| 14 |
type SchemaCacheEntry struct { |
| 15 |
Schema *base.Schema |
| 16 |
RenderedInline []byte |
| 17 |
ReferenceSchema string // String version of RenderedInline |
| 18 |
RenderedJSON []byte |
| 19 |
CompiledSchema *jsonschema.Schema |
| 20 |
RenderedNode *yaml.Node |
| 21 |
} |
| 22 |
|
| 23 |
// SchemaCache defines the interface for schema caching implementations. |
| 24 |
// The key is a uint64 hash of the schema (from schema.GoLow().Hash()). |
| 25 |
type SchemaCache interface { |
| 26 |
Load(key uint64) (*SchemaCacheEntry, bool) |
| 27 |
Store(key uint64, value *SchemaCacheEntry) |
| 28 |
Range(f func(key uint64, value *SchemaCacheEntry) bool) |
| 29 |
} |