<p>I'm writing an HTTP Cache library for Java, and I'm trying to use that library in the same application which is started twice. I want to be able to share the cache between those instances.</p>

<p>What is the best solution for this? I also want to be able to write to that same storage, and it should be available for both instances.</p>

<p>Now I have a memory-based index of the files available to the cache, and this is not shareable over multiple VMs. It is serialized between startups, but this won't work for a shared cache.</p>

<p>According to the HTTP Spec, I can't just map files to URIs as there might be a variation of the same payload based on the request. I might, for instance, have a request that varies on the 'accept-language' header: In that case I would have a different file for each subsequent request which specifies a different language.</p>

<p>Any Ideas?</p>

I think you should have a look at the
WebDav-Specifications
. It's an HTTP extension for sharing/editing/storing/versioning resources on a server. There exists an implementation as an
Apache module
, wich allows you a swift start using them.
So instead of implementing your own cache server implementation, you might be better off with a local Apache + mod-dav instance that is available to both of your applications.
Extra bonus: Since WebDav is a specified protocoll you get the interoperability with lots of tools for free.