dirmgr: add Store trait & MemoryStore impl
As discussed in #267 (closed), here goes the Store
trait to abstract the caching done in tor-dirmgr. To actually try it out, I've also added a MemoryStore
(behind a feature flag) that shows how to select between two Store
implementation (and that can be used in wasm!).
-
Store
trait is mostly allpub fn
fromSqliteStore
, minus the constructors- also, removed the use of iterator as dynamic object can't be parametrized per function
-
MemoryStore
is selected for tests when the feature is activated - configuration is a bit more complex now, as one can select between two
Store
impl. I'm sure that you've a nicer way to do it😅 - also, it kinda duplicates configuration as
arti_client::StorageCacheConfig::Sqlite
usesCfgPath
buttor_dirmgr::StorageConfig::Sqlite
usesPathBuf
- and sadly
derive_builder
doesn't supports nested builder, so that less nice than wanted (config.cache(StorageCacheConfig::Sqlite{ directory: CfgPath::new("/tmp".to_owned()) })
vsconf.storage().sqlite("/tmp")
👀 )
- also, it kinda duplicates configuration as
[storage]
cache = { sqlite = { directory = "${ARTI_CACHE}" } }
# cache = "memory"
NB: this PR is actually not really useful for fixing #267 (closed), as having hooks or a custom DirProvider
does the trick, but I coded it, hopefully it'll help you
Edited by tharvik