Class: Astronoby::CacheKey

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

Class Method Summary collapse

Class Method Details

.generate(type, instant, *components) ⇒ Array

Generate a cache key with appropriate precision

Parameters:

  • type (Symbol)

    The calculation type (e.g., :geometric, :nutation)

  • instant (Astronoby::Instant)

    The time instant

  • components (Array)

    Additional components for the key

Returns:

  • (Array)

    The complete cache key



170
171
172
173
174
175
176
# File 'lib/astronoby/cache.rb', line 170

def generate(type, instant, *components)
  return nil unless Astronoby.configuration.cache_enabled?

  precision = Astronoby.configuration.cache_precision(type)
  rounded_tt = round_terrestrial_time(instant.tt, precision)
  [type, rounded_tt, *components]
end

.round_terrestrial_time(tt, precision) ⇒ Numeric

Round terrestrial time to specified precision

Parameters:

  • tt (Numeric)

    Terrestrial time value

  • precision (Numeric)

    Precision in seconds

Returns:

  • (Numeric)

    Rounded time value



182
183
184
185
186
# File 'lib/astronoby/cache.rb', line 182

def round_terrestrial_time(tt, precision)
  return tt if precision <= 0

  tt.round(precision)
end