bigdata4u / spymemcached

Automatically exported from code.google.com/p/spymemcached
0 stars 0 forks source link

can spymemcached cause race condition? #318

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago

we are using 2.8.4 client version to connect to ElasticCache aws.  The problem 
I noticed on my qa env is that I find different version of data getting 
represented by memcached. seems like race condition happening:

my code:
cacheService is injected to my class:

public String getValue(String key) {
        String val = cacheService.get(getCacheKey(key));
        if (val != null) return val;
        List<AppConfig> appConfigs = find("{key:#}", key);
        if (appConfigs != null && appConfigs.size() > 0){
            AppConfig appConfig = appConfigs.get(0);
            cacheService.set(getCacheKey(appConfig.getKey()), appConfig.getValue());
            return appConfig.getValue();
        } else {
            return "";
        }
    }  

public boolean setValue(String key, String value) {
        AppConfig appConfig =this.getKeyValue(key);
        if (appConfig == null){
            appConfig = new AppConfig(key,value);
        }else{
            appConfig.setValue(value);
        }
        cacheService.set(getCacheKey(appConfig.getKey()), appConfig.getValue());
        return save(appConfig);

    }

public boolean deleteKey(String key) {
        cacheService.remove(getCacheKey(key));
        AppConfig appConfig =this.getKeyValue(key);
        if (appConfig == null){
            return false;
        }
       return this.removeById(appConfig.getId());
    }

Anything wrong with the way I get and set the key and data in my memcache?

Original issue reported on code.google.com by nahri...@yahoo.com on 26 Feb 2015 at 8:05