Couchbase
  • Why NoSQL?
  • Couchbase Server
  • Download
  • Resources
  • Careers
Home | Forums | Membase | Membase Server 1.6.x

Secondary key

3 replies [Last post]
  • Login or register to post comments
Sat, 03/19/2011 - 01:49
superwebs
Offline
Joined: 03/19/2011
Groups: None

We would like to use membase to build a cache of complicate price calculations. Our problem is that we need to clear the cache for single product when the user changes prices and not the entire cache.

For example:

Product 1 | Parameters | Price 1
Product 1 | Parameters | Price 2
Product 2 | Parameters | Price 1

When the user changes the system prices for product 1 we need to clear the cache but not for product 2.

We are currently doing this in MySQL but this is resulting in a huge number of inserts (the cache table usually contains 3-5 million records) and in our tests membase is significantly faster.

Is there any way of doing this with membase?

Top
  • Login or register to post comments
Wed, 03/23/2011 - 16:44
perry
Offline
Joined: 10/11/2010
Groups:

Hi there, thanks for your inquiry.

You could accomplish this in a number of ways:
-Use our TAP interface to stream out all the data from Membase and issue deletes for the keys that match a given product. The added advantage here is that you can connect to a TAP stream and be notified when a given key is changed in order to trigger a delete if you like.
-Setup separate buckets for each product so that you can manage each individually. I doubt this will actually be useful to you if you have millions of products, but thought it was worth pointing out.
-Our 2.0 release will include querying and indexing via CouchDB so that you can "search" for keys matching a given product and issue deletes for them.

How does that all sound?

Perry

__________________

Forum support is great for free but sometimes you need a guaranteed response time and dedicated resources for your questions or issues.
Consider purchasing enterprise-level support from Couchbase: http://www.couchbase.com/products-and-services/overview
Call or email "sales -at- couchbase-dot- com" today!

Top
  • Login or register to post comments
Thu, 03/24/2011 - 01:35
superwebs
Offline
Joined: 03/19/2011
Groups: None

Thanks for the reply. This sounds very encouranging.

When is the v2.0 release expected?

Top
  • Login or register to post comments
Thu, 03/24/2011 - 04:06
Steven
Offline
Joined: 10/01/2010
Groups: None

Hi

I have have the same problem, I got around this by building the key for the product from other stored keys, below is some snippets from my memcached wrapper class

    public function save($id, $data, $group = '', $ttl = null)
    	{
    	$ttl = ($ttl > 0)?time()+$ttl:0;
    	if ($this->_options['compression']){
           	$flag = MEMCACHE_COMPRESSED;
        }
    	else{
           	$flag = 0;
        }
        $id = $this->_id($id,$group);
    	$return = $this->_memcache->set($id, array($data, time()), $flag, $ttl);
    	return $return;
    	}
 
    public function valid($id, $group = ''){
        $data = $this->get($id,$group);
        if(is_array($data)){
            return $data[1];
        }
        return false;
        }
 
    public function get($id, $group = ''){
        $data = null;
        $id = $this->_id($id,$group);
    	$data = $this->_memcache->get($id);
    	if (is_array($data)){
           	return $data[0];
        }
        return null;
    	}
 
    public function destroy($id, $group = '')
    	{
    	$id = $this->_id($id,$group);
    	return $this->_memcache->delete($id,0);
    	}
 
    public function flush($group = ''){
    	if(!empty($group)){
    	    $groupName = $this->_options['prefix'].'-'.$group;
            return $this->destroy('internal-group-'.$groupName);
    	}
    	return $this->_memcache->flush();
    	}
 
    private function _id($key, $group = ''){
        if(!empty($group)){
            $groupName = $this->_options['prefix'].'-'.$group;
            $groupKey = $this->get('internal-group-'.$groupName);
            if(empty($groupKey)){
                $groupKey = substr($this->hash(microtime()),0,16);
                $this->save('internal-group-'.$groupName,$groupKey,'',(3600*24*7));
            }
            $returnKey = $groupKey.'::'.$key;
        }
        else{
            $returnKey = $key;
        }
        if(strlen($returnKey) > 250){ //quick hack to sort key lenght limit
        	$returnKey = $this->hash($returnKey);
        }
        return $returnKey;
        }
 
    protected function hash($str)
	{
	return md5($str).':'.md5(strrev($str));
	}

this might give some help on how to solve your problem.

Steven

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