Couchbase SDK issue, values not getting added to the store
Hi,
Im having an issue when using the .net SDK for couchbase. I am adding values to the cache using this line:
bool InternalAddToCache(string key, T cacheItem){ return new CouchbaseClient().Store(StoreMode.Set, key, cacheItem, new Timespan(0,5,0)); }
When I retrieve it back using this line, it comes back great:
T InternalRetrieveFromCache(string key) {
return new CouchbaseClient().Get(key); }
The item expires after 30 minutes and then a subsequent retrieve returns null (all sounds good so far). So after realising that the value is not in cache, I want to re-add it to the cache and store it for another 30 minutes. But when I attempt to add it again couch base returns false and its not added. What am I doing wrong? Can you not add the same key again after its expired? Is there a way to remove it cleanly so I can reuse that key again?
- I have installed couchbase locally (on the same machine I am developing on).
- Developing in visual studio 2010 (.net 4.0)
- Running couchbase on windows server 2008
- Version 1.8 of couchbase server
- 2.12.0.0 Enyim.Caching dll
- 1.0.0.0 Couchbase dll
Thanks in advance for any help!
Rob
Hi,
Thanks for getting back. The api doesnt seem to have that method (I do see it documented) but its not there in code.
new CouchbaseClient().Get(T)(Key) code doesnt have new CouchbaseClient().ExecuteGet(key) method
Any ideas where I should look for it?
Thanks!
Rob
Most probably you're missing "using Enyim.Cache" directive.
AFAIR Couchbase assembly contains only the basic get methods.
To gain further insight into your problem you could set up logging (as documented with the SDK).
You'll be able to see all the errors that occur along the way.
Cheers!
Michal
Thanks for the reply!
I have looked at that particular DLL and the only class I can see that allows me to cache is the MemcacheClient but it has no execute methods. Would you possibly be able to supply me with the line of code to do this?
Thanks again!
Rob
Hi Rob,
A couple of questions/points...
The ExecuteStore and other Execute methods are from v1.1 of the client, so double check that you're using that release. It's the current download...
Also, you don't want to create the client each time you execute an operation. When you create a client, there's an expensive bootstrapping process that should only be executed once. Creating a static instance of the client is generally best practice.
I just ran a simple test and didn't see this behavior:
var config = new CouchbaseClientConfiguration();
config.Urls.Add(new Uri("http://localhost:8091/pools/default"));
var client = new CouchbaseClient(config);
client.Store(StoreMode.Set, "somekey", "somevalue", TimeSpan.FromSeconds(30));
Console.WriteLine("Before sleep: " + client.Get("somekey"));
Thread.Sleep(40000);
Console.WriteLine("After sleep: " + client.Get("somekey"));
client.Store(StoreMode.Set, "somekey", "somevalue", TimeSpan.FromSeconds(30));
Console.WriteLine("After sleep and set: " + client.Get("somekey"));The result:
Before sleep: somevalue After sleep: After sleep and set: somevalue Press any key to continue . . .
If you run this code, do you see the same result?
Thanks.
-- John
Try ExecuteGet rather than Get and check Message and Error properties of the returned object.