I am using Couchbase 3.o with .Net SDK (V2.0). I am using it as distributed cache. I need to implement "Clear" method to clear all items in cache. That translates to deleting all documents in bucket. I do not see any method on Bucket or Cluster to do so. Is there some other API that I can use?
Thanks
The Couchbase .NET SDK has a flush command, here is an example of how to use it:
var configuration = new ClientConfiguration
{
Servers = new List<Uri>
{
new Uri(ConfigurationManager.AppSettings["bootstrapUrl"])
}
};
using (var cluster = new Cluster(configuration))
{
using (var bucket = cluster.OpenBucket())
{
var manager = bucket.CreateManager("Administrator", "");
var result = manager.Flush();
Assert.IsTrue(result.Success);
}
}
The keyword you are looking for is "flush". It is for just such a task. I know there is a REST API call to do this on the server, but I think there is a way in the .NET SDK 2.0 to do this as well. Just make sure you turn on the flush capability at the bucket level on the server. Otherwise it will never work.
As an overall cache invalidation strategy, I'd rather see you set a TTL on each piece of data you put into Couchbase and let Couchbase delete those objects over time instead of the overhead of dumping the cache the way you are talking about.
On a completely different note, make sure you are using the GA version of the 2.0 .NET SDK as it just came out the other day and Couchbase 3.0.1 as there was a nasty bug in the 3.0 release.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With