Class: Fontisan::Variation::CacheKeyBuilder
- Inherits:
-
Object
- Object
- Fontisan::Variation::CacheKeyBuilder
- Defined in:
- lib/fontisan/variation/cache_key_builder.rb
Overview
Builds cache keys for variation calculations
This class centralizes cache key generation with consistent formatting and efficient string construction. All variation caches should use this builder to ensure key compatibility.
Class Method Summary collapse
-
.blend_key(blend_index, scalars) ⇒ String
Build cache key for blend operations.
-
.custom_key(prefix, *components) ⇒ String
Build custom cache key.
-
.glyph_deltas_key(glyph_id, coordinates) ⇒ String
Build cache key for glyph deltas.
-
.instance_key(font_checksum, coordinates) ⇒ String
Build cache key for font instance.
-
.interpolation_key(base_value, deltas, scalars) ⇒ String
Build cache key for interpolated value.
-
.metrics_deltas_key(metrics_type, glyph_id, coordinates) ⇒ String
Build cache key for metrics deltas.
-
.region_matches_key(coordinates, regions) ⇒ String
Build cache key for region matches.
-
.scalars_key(coordinates, axes) ⇒ String
Build cache key for scalars.
Class Method Details
.blend_key(blend_index, scalars) ⇒ String
Build cache key for blend operations
Generates key for CFF2 blend operator results.
140 141 142 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 140 def blend_key(blend_index, scalars) "blend:#{blend_index}:#{scalars.join(',')}" end |
.custom_key(prefix, *components) ⇒ String
Build custom cache key
Generates key with custom prefix and components. Use for specialized caching needs.
156 157 158 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 156 def custom_key(prefix, *components) "#{prefix}:#{components.join(':')}" end |
.glyph_deltas_key(glyph_id, coordinates) ⇒ String
Build cache key for glyph deltas
Generates key for cached glyph delta application results.
106 107 108 109 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 106 def glyph_deltas_key(glyph_id, coordinates) sorted_coords = coordinates.sort.to_h "glyph:#{glyph_id}:#{sorted_coords}" end |
.instance_key(font_checksum, coordinates) ⇒ String
Build cache key for font instance
Generates key for entire instance generation result. Coordinates are sorted to ensure consistency.
71 72 73 74 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 71 def instance_key(font_checksum, coordinates) sorted_coords = coordinates.sort.to_h "instance:#{font_checksum}:#{sorted_coords}" end |
.interpolation_key(base_value, deltas, scalars) ⇒ String
Build cache key for interpolated value
Generates key based on base value, deltas, and scalars. Useful for caching individual interpolation results.
55 56 57 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 55 def interpolation_key(base_value, deltas, scalars) "interp:#{base_value}:#{deltas.join(',')}:#{scalars.join(',')}" end |
.metrics_deltas_key(metrics_type, glyph_id, coordinates) ⇒ String
Build cache key for metrics deltas
Generates key for cached metrics variation results.
123 124 125 126 127 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 123 def metrics_deltas_key(metrics_type, glyph_id, coordinates) sorted_coords = coordinates.sort.to_h glyph_part = glyph_id ? ":#{glyph_id}" : "" "metrics:#{metrics_type}#{glyph_part}:#{sorted_coords}" end |
.region_matches_key(coordinates, regions) ⇒ String
Build cache key for region matches
Generates key based on coordinates and region hash. Region hash is used to quickly identify region set without serializing entire region data.
89 90 91 92 93 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 89 def region_matches_key(coordinates, regions) sorted_coords = coordinates.sort.to_h region_hash = regions.hash "regions:#{sorted_coords}:#{region_hash}" end |
.scalars_key(coordinates, axes) ⇒ String
Build cache key for scalars
Generates a deterministic key based on axis tags and coordinate values. Axes are sorted to ensure consistent keys regardless of hash order.
36 37 38 39 40 |
# File 'lib/fontisan/variation/cache_key_builder.rb', line 36 def scalars_key(coordinates, axes) = axes.map(&:axis_tag).sort coord_values = .map { |tag| coordinates[tag] || 0.0 } "scalars:#{.join(',')}:#{coord_values.join(',')}" end |