Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disk cache #145

Merged
merged 3 commits into from
Feb 24, 2024
Merged

disk cache #145

merged 3 commits into from
Feb 24, 2024

Conversation

tirithen
Copy link
Contributor

@tirithen tirithen commented Jan 4, 2023

This is a draft for disk cache, still only supports sync, and have incomplete proc macro setup.

It would be helpful with some feedback one the src/stores/disk.rs code so far, to see if it goes into the correct direction.

Copy link
Owner

@jaemk jaemk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great! Thanks for getting started on it. Left a few comments

let now = SystemTime::now();
let last_cleanup = DiskCache::<K, V>::last_cleanup(connection);

if last_cleanup + Duration::from_secs(10) < now {
Copy link
Owner

@jaemk jaemk Jan 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we remove the interval logic, just have this do the full scan, and make it public? I think we might want to remove this call from the cache functions since this could end up causing every cache retrieval to do a full scan if you aren't frequently calling a function. Having it available for users to manually call would be good though so you can choose how to periodically call it (threads or async tasks)

Comment on lines 43 to 49
pub fn new<S: AsRef<str>>(prefix: S, seconds: u64) -> DiskCacheBuilder<K, V> {
Self {
seconds,
refresh: false,
namespace: DEFAULT_NAMESPACE.to_string(),
prefix: prefix.as_ref().to_string(),
disk_path: None,
_phantom_k: Default::default(),
_phantom_v: Default::default(),
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking that we create an individual sled-file for each disk-cache to simplify things. Then the namespace and prefix could go away and the disk-path would be required. We could keep fn disk_path below and repurpose it to generate a valid path for you from a string, so when the macro is constructing a DiskCache it can call disk_path($function_name) to get a per-function disk-cache. Thoughts?

}

fn cache_set(&self, key: K, value: V) -> Result<Option<V>, DiskCacheError> {
// TODO: wrap value when serializing to also add expiration data, then add separate thread to clean up the cache?
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should stay away from implicitly spawning any background threads here. Providing a way for users to call some function would be enough

namespace: String,
prefix: String,
disk_path: Option<PathBuf>,
_phantom_k: PhantomData<K>,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can combine these two lines to phantom: PhantomData<(K, V)>

@jqnatividad
Copy link
Contributor

Hi @tirithen , was just wondering if this is still WIP...

@tirithen
Copy link
Contributor Author

Hi @jqnatividad ! I have not been able to find the time to continue on this sadly, I still think that it would be a really useful feature as long as the API stays as simple and automatic as possible, or at least if there is a simple automatic optional API, but I there might be some time before I find time to continue this, so maybe it will need to be paused for now unless someone else finds the time.

@jaemk jaemk mentioned this pull request Feb 21, 2024
4 tasks
@jaemk jaemk changed the title draft for disk cache disk cache Feb 21, 2024
@jaemk jaemk changed the title disk cache draft for disk cache Feb 21, 2024
@jaemk jaemk changed the title draft for disk cache disk cache Feb 24, 2024
@jaemk jaemk marked this pull request as ready for review February 24, 2024 04:24
@jaemk jaemk merged commit 1099008 into jaemk:master Feb 24, 2024
1 check passed
@bschreck bschreck mentioned this pull request Mar 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants