Is Riak bucket object cachable?

78 Views Asked by At

When using Basho's Python client, getting a value for a key consists of two operations:

  • getting a bucket
  • getting a value from a bucket

Like this:

bucket = client.bucket(bucket_name)
value = bucket.get(key)

I occasionally get None back for the very same bucket. That seems nonsensical because the bucket is clearly there (I checked manually all the nodes client is created with). So the question is, can/should I cache/locally store the bucket object?

1

There are 1 best solutions below

1
On

I'm not an expert with the python client, but as far as I understand, you should keep your client.bucket instance around and use it multiple time to perform operations on it. However, I wouldn't cache it, if by caching you mean serialize it to disk or store it in a shared memory cache. Actually I would also avoid sharing it accross multiple threads. And definitely not across different processes.

Getting a bucket instance is cheap enough that you can create it quite often. However it's best practice to keep it and issue multiple operations on it in tight loops or while you haven't finished the current work.

If you use some connection pools, make sure you recreate your bucket instances when you reconnect.

Hope that helps. If not, give us more details, maybe show us some code :)