Class: VersionTagsPersistentCache
- Inherits:
-
Object
- Object
- VersionTagsPersistentCache
- Defined in:
- lib/spm_version_updates/version_tags_persistent_cache.rb
Overview
Persistent on-disk cache for successful git tag lookups restored by actions/cache.
Constant Summary collapse
- DEFAULT_TTL_SECONDS =
21_600- SCHEMA_VERSION =
1
Class Method Summary collapse
Instance Method Summary collapse
- #enabled? ⇒ Boolean
-
#initialize(directory:, ttl_seconds:, clock: -> { Time.now.utc }) ⇒ VersionTagsPersistentCache
constructor
A new instance of VersionTagsPersistentCache.
- #read(cache_key) ⇒ Object
- #write(cache_key, versions) ⇒ Object
Constructor Details
#initialize(directory:, ttl_seconds:, clock: -> { Time.now.utc }) ⇒ VersionTagsPersistentCache
Returns a new instance of VersionTagsPersistentCache.
19 20 21 22 23 |
# File 'lib/spm_version_updates/version_tags_persistent_cache.rb', line 19 def initialize(directory:, ttl_seconds:, clock: -> { Time.now.utc }) @directory = directory.to_s @ttl_seconds = ttl_seconds.to_i @clock = clock end |
Class Method Details
.cache_key(normalized_url, repository_url) ⇒ Object
15 16 17 |
# File 'lib/spm_version_updates/version_tags_persistent_cache.rb', line 15 def self.cache_key(normalized_url, repository_url) Digest::SHA256.hexdigest("#{normalized_url}\n#{CredentialRedactor.redact(repository_url)}") end |
Instance Method Details
#enabled? ⇒ Boolean
25 26 27 |
# File 'lib/spm_version_updates/version_tags_persistent_cache.rb', line 25 def enabled? !@directory.empty? && @ttl_seconds.positive? end |
#read(cache_key) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/spm_version_updates/version_tags_persistent_cache.rb', line 29 def read(cache_key) return nil unless enabled? record = read_record(cache_key) return nil unless fresh_record?(record) versions_from(record) end |
#write(cache_key, versions) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/spm_version_updates/version_tags_persistent_cache.rb', line 38 def write(cache_key, versions) return unless enabled? write_record(cache_key, versions) rescue StandardError => error warn("Failed to write to persistent cache: #{error.}") end |