Skip to content

Dynamic entry ttl. #246

@ruseinov

Description

@ruseinov

I'm building a daemon that needs to cache entries with TTL based on a configuration parameter.

The current approach is as follows:

#[once(time = 2, result = true, sync_writes = true)]
async fn estimate_fees() -> Result

This means that the TTL can only be specified once per function. What would be nice is the ability to specify the TTL dynamically.

Some options:
a. Based on function params: async fn estimate_fees(ttl: Duration, other_params..), that could be configured similar to key generation.
b. Perhaps a memoized method could be defined within a body of another method, which would then pass the ttl param

fn some_method(config: Config) {

define_cache! {
  CACHE;
  cache_ttl = config.ttl
  sync_writes = true
  result = true
  async fn estimate_fees() -> Result
}

}

Or even a more manual implementation, as long as it provides quick read-only functionality and synchronized writes (to do the init only once per TTL, since this is quite an expensive operation).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions