-
Notifications
You must be signed in to change notification settings - Fork 792
Conversation
84c99a2
to
a4405f8
Compare
a4405f8
to
2e05148
Compare
assert_eq!(res, 100.into()); | ||
|
||
assert!(!provider.cache().unwrap().requests.is_empty()); | ||
dbg!(&provider.cache()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dbg!(&provider.cache()); |
|
||
impl Drop for Cache { | ||
fn drop(&mut self) { | ||
let file = match File::options().write(true).read(true).create(true).open(&self.path) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be File::create
? which
Opens a file in write-only mode. reate a file if it does not exist, and will truncate it if it does.
pub struct Cache { | ||
path: PathBuf, | ||
// serialized request / response pair | ||
requests: DashMap<String, String>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be <String, serde_json::Value>?
@brockelmore curious what you think on this approach? |
Depending on how forge implements its caching strategy, it might be useful to have a way to clear the cache |
Closing - will make it part of the Forking provider on Foundry foundry-rs/foundry#835 |
Problem
We want to avoid repeating requests which we expect to have the same response. This is useful when used together with Forge's mainnet forking tests.
Solution
Add a
Cache
which stores all request/responses pairs in-memory, which then proceeds to store them in disk when it gets Dropped