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

Bulk remove on IDistributedCache #36568

Open
Tracked by #77390
ehabelgindy opened this issue Jul 28, 2015 · 6 comments
Open
Tracked by #77390

Bulk remove on IDistributedCache #36568

ehabelgindy opened this issue Jul 28, 2015 · 6 comments

Comments

@ehabelgindy
Copy link

Would it be useful if the IDistibutedCache interface can allow bulk remove?

Unlike the memory cache, removing multiple entries from distributed caches can be an expensive task. Providing an overload of the Remove function that accept an array of keys - e.g. Task Remove(string [] keys) - would allow more efficient implementations of distributed caches.

@RehanSaeed
Copy link

I posted an IDistributedCache helper which clears the cache and also bulk removes keys here, just in case someone finds it useful.

@SimonOrdo
Copy link

@RehanSaeed It looks like you're missing IDistributedCacheExtended definition in your post.

@eerhardt
Copy link
Member

We've reached feature complete for .NET 6. Moving to 7.

@eerhardt eerhardt modified the milestones: 6.0.0, 7.0.0 Jul 19, 2021
@deeprobin
Copy link
Contributor

deeprobin commented Jun 12, 2022

MemoryCache already implements this (see #45593). I think we can tag this as api-suggestion. However, this API would also be a breaking-change, due to other non-BCL implementations of the interface.

Here my proposal:

namespace Microsoft.Extensions.Caching.Distributed
{
    public interface IDistributedCache
    {
        void Clear();
        // Maybe, a ValueTask would not be a bad idea, but other Async APIs use a normal Task in this class.
        Task ClearAsync(CancellationToken cancellationToken = default);
    }

    public partial class MemoryDistributedCache : IDistributedCache {
        public void Clear();
        public Task ClearAsync(CancellationToken cancellationToken = default);
    }
}

namespace Microsoft.Extensions.Caching.Redis
{
    public partial class RedisCache : IDisposable, IDistributedCache {
        public void Clear();
        public Task ClearAsync(CancellationToken cancellationToken = default);
    }
}

namespace Microsoft.Extensions.Caching.StackExchangeRedis
{
    public partial class RedisCache : IDisposable, IDistributedCache {
        public void Clear();
        public Task ClearAsync(CancellationToken cancellationToken = default);
    }
}

namespace Microsoft.Extensions.Caching.SqlServer
{
    public partial class SqlServerCache : IDistributedCache {
        public void Clear();
        public Task ClearAsync(CancellationToken cancellationToken = default);
    }
}

@deeprobin
Copy link
Contributor

  • The interface can't be changed, per our breaking change rules.

Originally posted by @bartonjs in #45593 (comment)

It would probably make sense to update only the implementations and not change the interface due to the breaking change.

@eerhardt
Copy link
Member

We have started using Default Interface Members (DIMs) in Microsoft.Extensions. This may be a candidate to add in .NET 6.0+ APIs just like we did for #66479.

Here my proposal:

I don't believe the original intention of this issue is to remove all the entries from the cache, but remove a set of them specified by a collection of keys.

@adamsitnik adamsitnik modified the milestones: 8.0.0, 9.0.0 Jul 28, 2023
@adamsitnik adamsitnik modified the milestones: 9.0.0, Future Jul 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants