This document is a brief introduction to Coconut Cache. This guide is far from covering all aspects of the Coconut Cache or even most of them. It will only describe some of the most basic ways to accomplish a few of the most common tasks.
We assume that you are already familiar with a Java editor, such as Eclipse or Netbeans, or executing Java applications from the command line.
Download and Installation
In the following examples we will use the standalone jar version available for coconut cache. If you need the source code or the API documentation you can download the complete distribution here.
- Download the standalone jar from here.
- Add the jar to the classpath.
- Try running the one of the examples on this page.
If you are you
Putting stuff into a cache and getting it back out again
This is pretty much the simplest example possible. It creates a new unsynchronized cache, adds a single String to the cache and retrieves it from the cache and prints it out.
This is pretty similar to how you would use a
java.util.Map for storing elements. In fact, the main cache interface org.coconut.cache.Cache extends from java.util.Map. So you can use features such as the various collection views to iterate though all elements in a cache.
Configuration of the cache
Now, the unsynchronized cache we constructed previously just used the default cache settings. But most likely you will need to configure it in some way before you create it. To configure a Cache you will need to create an instanceof of a CacheConfiguration that is used to populate the cache with user specified settings. For example.
Notice that we create an instance of a SynchronizedCache this time and an UnsynchronizedCache. Since JMX uses threads (other then the main thread) to monitor the properties of the cache we need to make multiple threads can access the cache. Think of UnsynchronizedCache as a pendent to the unsynchronized java.util.HashMap and UnsynchronizedCache as an instance of the (thread-safe) java.util.HashTable, you need to decide which type you want to use.
Services
One of the main purpoe
set maximum size
How do I learn More
We would suggest you start looking at the example with the loading service and the expiration service.
Check out some of the examples available in the source repository
