New Open Source Cache System
The SHOP.COM Cache System is now available at http://code.google.com/p/sccache/
The SHOP.COM Cache System is an object cache system that...
- is an in-process cache and external, shared Cache
- is horizontally scalable
- stores cached objects to disk
- supports associative keys
- is non-transactional
- can have any size key and any size data
- does auto-GC based on TTL
- is container and platform neutral
It was built in-house at SHOP.COM (by me) and has powered our website for years. We are open-sourcing it in the hope that it will be useful to others and to get some help in its maintenance.
This is our first open source attempt and we'd appreciate any help and comments.
Here's a FAQ:
Why another cache?
At SHOP.COM, we've tried almost every cache system there is. None of them do what we need.
What's different about SHOP.COM Cache?
* It doesn't try to be a database
* It can handle very large objects and very large keys
* Cached objects can survive a server crash
* Has both a local (in-memory) and external/shared cache
* Extremely fast - >20K operations a minute (depending on hardware)
* Highly scalable - sccache scales horizontally extremely well
What kinds of things can be cached?
Any Serializable object. In practice, it's common to cache database result sets, HTML pages, HTTP sessions, etc.
Why open source it?
Our cache was written by one engineer (me). We'd like more eyes on the code and help maintaining it.
How stable is the code?
sccache has been used at SHOP.COM in one form or another for 10 years. So, it's stable enough to use in our production environment. However, I've had to make some changes to separate it into an open source library. We are not currently running the open source version at SHOP.COM. I'll post when we make the change.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)





Comments
Dinh Pham Cong replied on Thu, 2008/12/18 - 9:53am
Jordan Zimmerman replied on Thu, 2008/12/18 - 12:00pm
in response to:
Dinh Pham Cong
Dinh Pham Cong replied on Thu, 2008/12/18 - 1:19pm
in response to:
Jordan Zimmerman
Jordan Zimmerman replied on Thu, 2008/12/18 - 2:38pm
in response to:
Dinh Pham Cong
>Does it implement the same built-in memory clustering mechanism as it can be seen in Terracotta?
As I understand it, Terracotta does something under the hood of the JVM so that the Java code transparently sees objects from other VMs. sccache does not work this way. It treats the external cache servers as a type of HashMap and writes/reads objects based on the hash of the object's key. I believe memcached, Coherence and JCS work this way as well.
Peter Maas replied on Thu, 2008/12/18 - 4:52pm
Jordan Zimmerman replied on Thu, 2008/12/18 - 5:13pm
in response to:
Peter Maas
The post contains both "is non-transactional" and "Extremely fast - >20K transactions a minute (depending on hardware)" ... I assume the latter to be an atomic write action to cache, or is it something different?
Yes, I'll correct that. I was using "transactional" with different meanings.
Jay Spring replied on Thu, 2008/12/18 - 8:18pm
Jordan Zimmerman replied on Thu, 2008/12/18 - 8:46pm
in response to:
Jay Spring
>exactly which parts of shop.com is this cache being used for?
We cache generated HTML pages, SQL queries, HTTP Sessions, POJO objects, etc.
Joe Farmer replied on Sat, 2008/12/20 - 5:49pm
Jordan Zimmerman replied on Sun, 2008/12/21 - 12:44am
in response to:
Joe Farmer
[quote=tech0513]How do you overcome file fragmentation after repeated record deletions? [/quote]
sccache uses a data store I wrote (called CCDB2). It's actually usable by itself if anyone's interested. It re-uses blocks if size allows it to. But, in general, fragmentation isn't an issue. Here's the alogrithm:
A maximum TTL must be chosen - at SHOP.COM we use 12 hours. Every
max/2hours, the current datafile is closed for new objects and a new datafile is created. Aftermax + max/2hours, you will have 3 datafiles. Atmax * 2hours, the third datafile is guaranteed to have nothing but stale objects and is deleted.Joe Farmer replied on Sun, 2008/12/21 - 9:41am
in response to:
Jordan Zimmerman
Joe Farmer replied on Sun, 2008/12/21 - 6:27pm
Created a quick test:
public class TestServer {
public static void main(String[] args) throws Exception {
SCServerFactory factory = ShopComCacheFactory.getServerFactory();
SCServerContext context = factory.newContext();
context.port(1111);
SCStorage db = CCDB2StorageFactory.create(new CCDB2Parameters());
db.open(new File("."));
SCServer server = factory.newServer(context, db);
server.join();
}
}
public class ClientWTest {
public static void main(String[] args) throws Exception {
SCCache myCache = getCache();
int max = 100;
for (int i = 0; i < max; i++) {
Person person = new Person(getName(i));
SCDataBlock block = new SCDataBlock(person.getName(), person);
block.canBeStoredInMemory(false);
block.canBeStoredExternally(true);
myCache.put(block);
}
}
static SCCache getCache() throws Exception {
SCClientFactory clientFactory = ShopComCacheFactory.getClientFactory();
SCClientContext context = clientFactory.newContext();
context.address(new InetSocketAddress("localhost", 1111));
SCClientManager manager = clientFactory.newClientManager(context);
return new SCCache(manager);
}
static String getName(int i) {
return "person" + i;
}
}
public class ClientRTest {
public static void main(String[] args) throws Exception {
SCCache myCache = ClientWTest.getCache();
for (int i = 0; i < 20; i++) {
SCDataBlock block = new SCDataBlock(ClientWTest.getName(i));
block.canBeStoredInMemory(false);
block.canBeStoredExternally(true);
Object value = myCache.get(block);
System.out.println("value [" + i + "] = " + value);
}
}
}
After that:
1. start the server
2. run ClientWTest
3. run ClientRTest - no results returned. Any ideas why? If it's of any help - only data file ccdb23747138201158134.db was created - no index file.
Thanks
Joe Farmer replied on Mon, 2008/12/22 - 1:14am
Jordan Zimmerman replied on Mon, 2008/12/22 - 1:55am
in response to:
Joe Farmer
Jordan Zimmerman replied on Tue, 2008/12/30 - 7:22pm
Issue:
http://code.google.com/p/sccache/issues/detail?id=1&can=1
Fix:
http://sccache.googlecode.com/files/sccache_0_4.zip
Jordan Zimmerman replied on Tue, 2009/01/27 - 8:28pm
Jordan Zimmerman replied on Fri, 2009/01/30 - 8:29pm
Jordan Zimmerman replied on Thu, 2009/05/21 - 1:19pm
A new patch is available:
http://code.google.com/p/sccache/
hookfi john replied on Sun, 2009/05/31 - 7:43am