Skip to content

Commit

Permalink
Merge pull request #203 from paterczm/cache
Browse files Browse the repository at this point in the history
Cache expires between isKeyInCache check and actually getting the key (?)
  • Loading branch information
bserdar committed Jun 5, 2015
2 parents 3ec16b3 + a9af9ff commit edbca31
Showing 1 changed file with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,29 +38,35 @@ public void push(Long id) {
long threadId = Thread.currentThread().getId();
if(log.isDebugEnabled())
log.debug("Storing id="+id+" for "+cache.getName()+", thread="+threadId);
if (!cache.isKeyInCache(threadId)) {
cache.put(new Element(threadId, new LinkedList<Long>()));
}

if (log.isDebugEnabled())
log.debug("cache("+threadId+")="+cache.get(threadId));
Element el = cache.get(threadId);
LinkedList<Long> list;

@SuppressWarnings("unchecked")
LinkedList<Long> list = (LinkedList<Long>)cache.get(threadId).getObjectValue();
if (el == null) {
list = new LinkedList<Long>();
}
else {
list = (LinkedList<Long>)el.getObjectValue();
}

list.add(id);

cache.put(new Element(threadId, list));
}

@Override
public Long pop() {
long threadId = Thread.currentThread().getId();
log.debug("Restoring id for "+cache.getName()+" thread="+threadId);
if (!cache.isKeyInCache(threadId)) {

Element el = cache.get(threadId);

if (el == null) {
throw new RuntimeException("No ids found for "+cache.getName()+" thread="+threadId+"!");
}

@SuppressWarnings("unchecked")
LinkedList<Long> list = (LinkedList<Long>)cache.get(threadId).getObjectValue();
LinkedList<Long> list = (LinkedList<Long>)el.getObjectValue();

try {
return list.removeFirst();
Expand Down

0 comments on commit edbca31

Please sign in to comment.