diff --git a/src/lib.rs b/src/lib.rs index 8e0a03b..91dfd31 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ use std::hash::{DefaultHasher, Hash, Hasher}; use std::path::PathBuf; +use std::time::Instant; use chrono::{DateTime, Duration, Utc}; use rusqlite::Connection; @@ -90,6 +91,19 @@ impl Cache { } pub fn store(&self, key: K, value: T) -> Result<(), Error> + where + K: Hash, + T: ToSql + FromSql, + { + self.store_with_expiration(key, value, Utc::now() + self.ttl) + } + + pub fn store_with_expiration( + &self, + key: K, + value: T, + expiration: DateTime, + ) -> Result<(), Error> where K: Hash, T: ToSql + FromSql, @@ -103,7 +117,7 @@ impl Cache { let value = CacheEntry { key: hash, value, - expiration: Utc::now() + self.ttl, + expiration, }; let db = Connection::open(self.path.as_path())?;