Class: ActiveSanction::ValidatorStore::FileSystem

Inherits:
ValidatorStore
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/active_sanction/validator_store/file_system.rb

Overview

Validators in one small JSON file, so a sync that runs from cron gets a 304 on its second run rather than on its second run within one process.

ActiveSanction::ValidatorStore::FileSystem.new
# => ~/.cache/active_sanction/validators.json

JSON, indented, keyed by the caller's key: this file is the first thing somebody opens when a sync is downloading more than it should, and it is a few hundred bytes even with every source in it. It is also the file the acceptance criterion is about -- deleting it forces a full re-download, and nothing else is lost with it, because validators are an optimization and never the record of what a list contained.

Entries are re-read on every access rather than memoized. The file is tiny, and a cache that has to be reloaded to see another process's write is a cache that lies to a sync running beside a CLI command.

Writes go to a temporary sibling and are renamed into place, so an interrupted write leaves the previous file rather than a truncated one. Two processes writing at once still resolve last-writer-wins: the cost is one avoidable download, which is the right trade for not putting a lock file in a user's cache directory.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path: nil) ⇒ void

Parameters:

  • path (T.untyped) (defaults to: nil)


43
44
45
46
47
48
# File 'lib/active_sanction/validator_store/file_system.rb', line 43

def initialize(path: nil)
  @path = T.let(
    ::File.expand_path((path || ::File.join(ActiveSanction.config.cache_dir, DEFAULT_FILENAME)).to_s), String
  )
  super()
end

Instance Attribute Details

#path ⇒ String (readonly)

Returns:

  • (String)


40
41
42
# File 'lib/active_sanction/validator_store/file_system.rb', line 40

def path
  @path
end

Instance Method Details

#inspect ⇒ String

Returns:

  • (String)


51
# File 'lib/active_sanction/validator_store/file_system.rb', line 51

def inspect = "#<#{self.class} #{path} #{size} entr#{size == 1 ? "y" : "ies"}>"