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

[Help wanted] Update expiration date #792

Open
seyfeb opened this issue Jul 13, 2022 · 3 comments
Open

[Help wanted] Update expiration date #792

seyfeb opened this issue Jul 13, 2022 · 3 comments

Comments

@seyfeb
Copy link

seyfeb commented Jul 13, 2022

Is there a way to update expiration dates of existing cached items, preferably without reading the object from a disk cache into memory and rewriting it back to the disk (think of large data objects)?

Use case: I query the server for updates of the object and get a NotModified response, so I simply want to update the expiration date of the already cached item.

@Sewer56
Copy link

Sewer56 commented Aug 10, 2022

I'm surprised this (overwriting expiration time) isn't a feature of Akavache personally.

There's some good use cases for this, as you can effectively set up a maximum lifetime for a given object but keep extending it for as long as you need it.

In my case, for example, I can determine I can keep an object for longer from a result of another API call; getting and then re-inserting it sounds silly and inefficient.

In any case, you can use a raw SQL query in the meantime; it's the only reflection-free method I can think of:

/// <summary>
/// Refreshes the expiration date of a given key.
/// </summary>
/// <param name="key">The key to be refreshed.</param>
/// <param name="newExpiration">New timespam of expiration relative to current.</param>
public void Refresh(string key, TimeSpan newExpiration)
{
    var expiration = _cache.Scheduler.Now + newExpiration;
    _cache.Connection.Execute($"UPDATE CacheElement SET Expiration='{expiration.Ticks}' WHERE Key='{key}'");
}

@anaisbetts
Copy link
Member

This would be a good feature to add

@cristhian-zarate
Copy link

I would like to add a use case. Similar to @Sewer56, I need to refresh the TTL of records when being accessed, but assign them the same expiration period they had before.
Unfortunately, I haven't been able to find a workaround while using the BlobCache.Secure location, because it does not expose the Connection property. (I opened a discussion thread asking if there is a way to find the expiration of a record when using BlobCache.Secure)
So, for me it would be useful to have a method like GetObjectAndRefresh<T>(string) and not have to potentially look up the Expiration of a record while reading its value and then inserting the record with its TTL again.

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

4 participants