toelen/spymemcached-jcache — Issue #1: put fails to overwrite existing values
Author: bejayoharen
Created: 2012-01-15 18:08:02+00:00
State: open

if a value exists in a cache, and put is called, the spec says it should overwrite:

https://jsr107.ci.cloudbees.com/job/jsr107api/ws/target/apidocs/index.html

However, in testing, the value is not replaced. memcached reports NOT_STORED and reading back finds the value is not replaced.

```import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.*;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.*;

import javax.cache.Cache;
import javax.cache.CacheManager;

import net.spy.memcached.jcache.SpyCachingProvider;

public class HelloWorld extends HttpServlet {
private static CacheManager cacheManager;
private static Cache cache;

static {
// -- setup cache
System.setProperty("spymemcachedservers", "localhost:11211");
SpyCachingProvider provider = new SpyCachingProvider();
cacheManager = provider.createCacheManager( provider.getDefaultClassLoader(), "default");
cache = cacheManager. createCacheBuilder("cacheName").build();
if( cache == null )
throw new NullPointerException();
}

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
Integer i = cache.get( "pagecount" );
System.out.println( "got: " + i );
if( i == null )
i = new Integer( 0 );
resp.getWriter().print("This page has been viewed " + i + " times.)\n");
i = i.intValue() + 1 ;
System.out.println( i );
System.out.println( "putting: " + i );
cache.remove("pagecount", i ); // -- required or the pagecount does not increment. SHOULD NOT BE NEEDED
cache.put( "pagecount", i );
}

public static void main(String[] args) throws Exception{
Server server = new Server(Integer.valueOf(System.getenv("PORT")));
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
server.setHandler(context);
context.addServlet(new ServletHolder(new HelloWorld()),"/*");
server.start();
server.join();
}
}
```