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

Ignore some arguments #67

Closed
omid opened this issue Dec 28, 2020 · 2 comments
Closed

Ignore some arguments #67

omid opened this issue Dec 28, 2020 · 2 comments

Comments

@omid
Copy link
Contributor

omid commented Dec 28, 2020

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!

pub fn get_user(conn: &PgConnection, user_id: &Uuid) -> MyResult<User>

My suggestion us to have something like:

#[cached(time = 600, ignore = "conn,another_param")]
pub fn get_user(conn: &PgConnection, user_id: &Uuid, another_param: String) -> MyResult<User>
@jaemk
Copy link
Owner

jaemk commented Dec 28, 2020

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)
}

@omid
Copy link
Contributor Author

omid commented Dec 28, 2020

Wow, thanks.
It is more complex than I thought.

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

No branches or pull requests

2 participants