Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | SDKs | SDKs

Couchbase SDK issue, values not getting added to the store

5 replies [Last post]
  • Login or register to post comments
Tue, 05/22/2012 - 05:09
rob.mccabe
Offline
Joined: 05/22/2012
Groups: None

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

 

Top
  • Login or register to post comments
Thu, 05/24/2012 - 06:11
r_o_o_k
Offline
Joined: 05/23/2012
Groups: None

Try ExecuteGet rather than Get and check Message and Error properties of the returned object.

Top
  • Login or register to post comments
Thu, 05/24/2012 - 07:14
rob.mccabe
Offline
Joined: 05/22/2012
Groups: None

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

Top
  • Login or register to post comments
Thu, 05/24/2012 - 07:18
r_o_o_k
Offline
Joined: 05/23/2012
Groups: None

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

Top
  • Login or register to post comments
Thu, 05/24/2012 - 08:35
rob.mccabe
Offline
Joined: 05/22/2012
Groups: None

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

Top
  • Login or register to post comments
Thu, 05/24/2012 - 16:41
john
Offline
Joined: 01/05/2012
Groups: None

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

Top
  • Login or register to post comments
  • Login or register to post comments
  • Login
  • Register

Company

  • About Us
  • Leadership
  • Customers
  • Partners
  • Contact Us

Product

  • Couchbase Server
  • Couchbase SDKs
  • Use Cases
  • Documentation
  • Forums

Open Source

  • Couchbase Project
  • Couchbase vs. CouchDB

Commercial

  • Subscriptions & Support
  • Training & Services

News

  • Blog
  • Newsletter
  • Press Releases
  • Buzz

Follow Us

    
  • Customer Login
  • Terms of Service
  • Privacy Policy
  • Trademark Policy
  • Site Map

© 2013 COUCHBASE All rights reserved.

Sign in to Couchbase Community

close
  • Create new account
  • Request new password
You are logging into the Forums, Wiki and Issue Tracker