Export to GitHub

spymemcached - issue #318

can spymemcached cause race condition?


Posted on Feb 26, 2015 by Happy Ox

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?

Status: New

Labels:
Type-Defect Priority-Medium