Class: ActiveSanction::ValidatorStore::FileSystem
- Inherits:
-
ValidatorStore
- Object
- ValidatorStore
- ActiveSanction::ValidatorStore::FileSystem
- 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
- #path ⇒ String readonly
Instance Method Summary collapse
- #initialize(path: nil) ⇒ void constructor
- #inspect ⇒ String
Constructor Details
#initialize(path: nil) ⇒ void
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.((path || ::File.join(ActiveSanction.config.cache_dir, DEFAULT_FILENAME)).to_s), String ) super() end |
Instance Attribute Details
#path ⇒ String (readonly)
40 41 42 |
# File 'lib/active_sanction/validator_store/file_system.rb', line 40 def path @path end |
Instance Method Details
#inspect ⇒ String
51 |
# File 'lib/active_sanction/validator_store/file_system.rb', line 51 def inspect = "#<#{self.class} #{path} #{size} entr#{size == 1 ? "y" : "ies"}>" |