Closed omid closed 3 years ago
You can use the type
, create
, and convert
options to get what you're looking for (also result = true
to cache only Ok
results):
#[cached(
result = true,
type = "TimedCache<uuid::Uuid, String>",
create = "{ TimedCache::with_lifespan(600) }",
convert = r#"{ user_id.clone() }"#
)]
pub fn get_user(conn: &PgConnection, user_id: &uuid::Uuid) -> MyResult<User> {
...
Ok(user)
}
Wow, thanks. It is more complex than I thought.
Is there any way of ignoring some of the arguments?
Imagine I have a method to get one user from the database. And I would like to cache the user. So this method may need two params, DB connection pool and the user ID. In my case, I do not care about connection pool uniqueness and would like to ignore it!
My suggestion us to have something like: