--- /dev/null
+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"));
+ }
+}
+
+
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);
--- /dev/null
+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<String> serverList) {
+ initCache(serverList.toArray(new String[]{}));
+ }
+}
+