File storage index share with multiple open applications in Java

I am writing an HTTP Cache Library for Java and I am trying to use this library in the same application that runs twice. I want to be able to share the cache between these instances.

What's the best solution for this? I also want to be able to write to the same repository and it needs to be available to both instances.

I now have an index based on the memory of the files available for the cache and this does not apply to multiple VMs. It gets serialized between startups, but this won't work for shared cache.

As per the HTTP spec, I cannot just map files to URIs as there might be a change to the same payload based on the request. For example, I might have a request that depends on the "accept-language" header: in this case, I will have a different file for each subsequent request that specifies a different language.

Any ideas?

+1


source to share


2 answers


First, are you sure you want to write your own cache when there are multiple around it? Such things as:

The first two are written in Java and the third is written in Java. I believe the first two refer to distributed caching, which is a general case of what you are asking for. When they start, they want to connect to other members so that they maintain a consistent cache between instances. Changes in one are reflected in different copies. They can be configured to connect via multicast or with specific lists of specified servers.



Memcached usually works a little differently as it works because of the external Java processes that you start, so all running Java instances will talk to the shared service. You can configure memcached to work in a distributed fashion, but this is done by hashing the keys so that the server you want to connect to can be determined by what you are looking for.

Implementing a true distributed cache with consistent content is very difficult to do well, so I suggest looking at the existing library. If you want to do it yourself, it still helps to take a look at the ones listed to see how they are going down that path and consider using something like JGroups as the main mechanism.

+1


source


I think you should take a look at the WebDav-Specifications . It is an HTTP extension for sharing / editing / storing / versioning on the server. There is an implementation as the Apache module that allows you to quickly use them.

So instead of implementing your own cache server implementation, you might be better off with a local Apache + mod-dav instance available to both of your applications.



Added bonus: Because WebDav is a specific protocol, you get the ability to interact with many tools for free.

0


source







All Articles