You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@hbase.apache.org by Li Li <fa...@gmail.com> on 2014/04/14 08:06:39 UTC

use hbase as a global cache

hi all
   I want to use hbase as a global cache. I need some advice .
   getFromCache(String key){
       get from hbase;
       if exist return result;
       value="working...";

       boolean res=checkAndPut;
       if(res){
              value=doWork(key);
              Put(key, value);
        }else{ //some other thread is doing work now
              //sleep a while and retry
              for(int i=0;i<MAX_RETRY;i++){
                    sleep;
                    get value from hbase
                    if(value!="working...") return value;
              }
              //some thing wrong happens such as working thread crash
              //do it myself
              value=doWork(key);
              Put(key,value);
              return value;
        }
     }

     btw, hbase has TTL for column family. is it possible to set ttl
per row/cell?

Re: use hbase as a global cache

Posted by Ted Yu <yu...@gmail.com>.
For per cell TTL, see https://issues.apache.org/jira/browse/HBASE-10560

Cheers

On Apr 13, 2014, at 11:06 PM, Li Li <fa...@gmail.com> wrote:

> hi all
>   I want to use hbase as a global cache. I need some advice .
>   getFromCache(String key){
>       get from hbase;
>       if exist return result;
>       value="working...";
> 
>       boolean res=checkAndPut;
>       if(res){
>              value=doWork(key);
>              Put(key, value);
>        }else{ //some other thread is doing work now
>              //sleep a while and retry
>              for(int i=0;i<MAX_RETRY;i++){
>                    sleep;
>                    get value from hbase
>                    if(value!="working...") return value;
>              }
>              //some thing wrong happens such as working thread crash
>              //do it myself
>              value=doWork(key);
>              Put(key,value);
>              return value;
>        }
>     }
> 
>     btw, hbase has TTL for column family. is it possible to set ttl
> per row/cell?