From 0c966ad90773b48c8e261ce55237b5df43c42685 Mon Sep 17 00:00:00 2001 From: erickson Date: Wed, 16 May 2007 19:30:03 +0000 Subject: [PATCH] added a memcache client and test git-svn-id: svn://svn.open-ils.org/ILS/trunk@7322 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- OpenSRF/src/java/org/opensrf/test/TestCache.java | 27 +++++++++++++++ .../src/java/org/opensrf/test/TestSettings.java | 2 -- OpenSRF/src/java/org/opensrf/util/Cache.java | 38 ++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 OpenSRF/src/java/org/opensrf/test/TestCache.java create mode 100644 OpenSRF/src/java/org/opensrf/util/Cache.java diff --git a/OpenSRF/src/java/org/opensrf/test/TestCache.java b/OpenSRF/src/java/org/opensrf/test/TestCache.java new file mode 100644 index 0000000000..1e47c329ae --- /dev/null +++ b/OpenSRF/src/java/org/opensrf/test/TestCache.java @@ -0,0 +1,27 @@ +package org.opensrf.test; +import org.opensrf.*; +import org.opensrf.util.*; +import java.util.List; +import java.util.ArrayList; + +public class TestCache { + public static void main(String args[]) throws Exception { + + /** + * args is a list of string like so: server:port server2:port server3:port ... + */ + + Cache.initCache(args); + Cache cache = new Cache(); + + cache.set("key1", "HI, MA!"); + cache.set("key2", "HI, MA! 2"); + cache.set("key3", "HI, MA! 3"); + + System.out.println("got key1 = " + (String) cache.get("key1")); + System.out.println("got key2 = " + (String) cache.get("key2")); + System.out.println("got key3 = " + (String) cache.get("key3")); + } +} + + diff --git a/OpenSRF/src/java/org/opensrf/test/TestSettings.java b/OpenSRF/src/java/org/opensrf/test/TestSettings.java index d176acf9f2..116bbe1683 100644 --- a/OpenSRF/src/java/org/opensrf/test/TestSettings.java +++ b/OpenSRF/src/java/org/opensrf/test/TestSettings.java @@ -6,8 +6,6 @@ public class TestSettings { public static void main(String args[]) throws Exception { Sys.bootstrapClient(args[0], "/config/opensrf"); SettingsClient client = SettingsClient.instance(); - //Object obj = client.get("/apps"); - //System.out.println(new JSONWriter(obj).write()); String lang = client.getString("/apps/opensrf.settings/language"); String impl = client.getString("/apps/opensrf.settings/implementation"); System.out.println("opensrf.settings language = " + lang); diff --git a/OpenSRF/src/java/org/opensrf/util/Cache.java b/OpenSRF/src/java/org/opensrf/util/Cache.java new file mode 100644 index 0000000000..53036886cc --- /dev/null +++ b/OpenSRF/src/java/org/opensrf/util/Cache.java @@ -0,0 +1,38 @@ +package org.opensrf.util; +import com.danga.MemCached.*; +import java.util.List; + +/** + * Memcache client + */ +public class Cache extends MemCachedClient { + + public Cache() { + super(); + setCompressThreshold(4096); /* ?? */ + } + + /** + * Initializes the cache client + * @param serverList Array of server:port strings specifying the + * set of memcache servers this client will talk to + */ + public static void initCache(String[] serverList) { + SockIOPool pool = SockIOPool.getInstance(); + pool.setServers(serverList); + pool.initialize(); + com.danga.MemCached.Logger logger = + com.danga.MemCached.Logger.getLogger(MemCachedClient.class.getName()); + logger.setLevel(logger.LEVEL_ERROR); + } + + /** + * Initializes the cache client + * @param serverList List of server:port strings specifying the + * set of memcache servers this client will talk to + */ + public static void initCache(List serverList) { + initCache(serverList.toArray(new String[]{})); + } +} + -- 2.11.0