You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by js...@apache.org on 2010/10/20 06:59:43 UTC

svn commit: r1024519 - in /tuscany/sca-cpp/trunk: components/cache/ samples/store-cluster/shared/ samples/store-sql/

Author: jsdelfino
Date: Wed Oct 20 04:59:43 2010
New Revision: 1024519

URL: http://svn.apache.org/viewvc?rev=1024519&view=rev
Log:
Renamed frontcache to datacache and add a memo cache that memoizes function applications.

Added:
    tuscany/sca-cpp/trunk/components/cache/adder-test.scm
    tuscany/sca-cpp/trunk/components/cache/cache.composite
      - copied, changed from r999229, tuscany/sca-cpp/trunk/components/cache/memcache.composite
    tuscany/sca-cpp/trunk/components/cache/datacache.cpp
      - copied, changed from r999229, tuscany/sca-cpp/trunk/components/cache/frontcache.cpp
    tuscany/sca-cpp/trunk/components/cache/memocache.cpp
Removed:
    tuscany/sca-cpp/trunk/components/cache/frontcache.cpp
    tuscany/sca-cpp/trunk/components/cache/memcache.composite
Modified:
    tuscany/sca-cpp/trunk/components/cache/Makefile.am
    tuscany/sca-cpp/trunk/components/cache/client-test.cpp
    tuscany/sca-cpp/trunk/components/cache/server-test
    tuscany/sca-cpp/trunk/samples/store-cluster/shared/shared.composite
    tuscany/sca-cpp/trunk/samples/store-sql/store.composite

Modified: tuscany/sca-cpp/trunk/components/cache/Makefile.am
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/Makefile.am?rev=1024519&r1=1024518&r2=1024519&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/Makefile.am (original)
+++ tuscany/sca-cpp/trunk/components/cache/Makefile.am Wed Oct 20 04:59:43 2010
@@ -25,18 +25,22 @@ comp_DATA = memcached.prefix
 memcached.prefix: $(top_builddir)/config.status
 	echo ${MEMCACHED_PREFIX} >memcached.prefix
 
-EXTRA_DIST = memcache.composite
+EXTRA_DIST = cache.composite
 
-comp_LTLIBRARIES = libmemcache.la libfrontcache.la
-noinst_DATA = libmemcache.so libfrontcache.so
+comp_LTLIBRARIES = libmemcache.la libdatacache.la libmemocache.la
+noinst_DATA = libmemcache.so libdatacache.so libmemocache.so
 
 libmemcache_la_SOURCES = memcache.cpp
 libmemcache.so:
 	ln -s .libs/libmemcache.so
 
-libfrontcache_la_SOURCES = frontcache.cpp
-libfrontcache.so:
-	ln -s .libs/libfrontcache.so
+libdatacache_la_SOURCES = datacache.cpp
+libdatacache.so:
+	ln -s .libs/libdatacache.so
+
+libmemocache_la_SOURCES = memocache.cpp
+libmemocache.so:
+	ln -s .libs/libmemocache.so
 
 memcache_test_SOURCES = memcache-test.cpp
 memcache_test_LDFLAGS = -lxml2

Added: tuscany/sca-cpp/trunk/components/cache/adder-test.scm
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/adder-test.scm?rev=1024519&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/adder-test.scm (added)
+++ tuscany/sca-cpp/trunk/components/cache/adder-test.scm Wed Oct 20 04:59:43 2010
@@ -0,0 +1,20 @@
+;  Licensed to the Apache Software Foundation (ASF) under one
+;  or more contributor license agreements.  See the NOTICE file
+;  distributed with this work for additional information
+;  regarding copyright ownership.  The ASF licenses this file
+;  to you under the Apache License, Version 2.0 (the
+;  "License"); you may not use this file except in compliance
+;  with the License.  You may obtain a copy of the License at
+;  
+;    http://www.apache.org/licenses/LICENSE-2.0
+;    
+;  Unless required by applicable law or agreed to in writing,
+;  software distributed under the License is distributed on an
+;  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+;  KIND, either express or implied.  See the License for the
+;  specific language governing permissions and limitations
+;  under the License.
+
+; Logger test case
+
+(define (add a b) (+ a b))

Copied: tuscany/sca-cpp/trunk/components/cache/cache.composite (from r999229, tuscany/sca-cpp/trunk/components/cache/memcache.composite)
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/cache.composite?p2=tuscany/sca-cpp/trunk/components/cache/cache.composite&p1=tuscany/sca-cpp/trunk/components/cache/memcache.composite&r1=999229&r2=1024519&rev=1024519&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/memcache.composite (original)
+++ tuscany/sca-cpp/trunk/components/cache/cache.composite Wed Oct 20 04:59:43 2010
@@ -38,10 +38,10 @@
         <property name="servers">localhost:11411,localhost:11412,localhost:11413</property>
     </component>
 
-    <component name="frontcache">
-        <implementation.cpp path="." library="libfrontcache"/>
-        <service name="frontcache">
-            <t:binding.http uri="frontcache"/>
+    <component name="datacache">
+        <implementation.cpp path="." library="libdatacache"/>
+        <service name="datacache">
+            <t:binding.http uri="datacache"/>
         </service>
         <reference name="l1reader" target="memcache"/>
         <reference name="l1writer" target="memcache"/>
@@ -49,4 +49,20 @@
         <reference name="l2writer" target="l2cache"/>
     </component>
 
+    <component name="memocache">
+        <implementation.cpp path="." library="libmemocache"/>
+        <service name="memocache">
+            <t:binding.http uri="memocache"/>
+        </service>
+        <reference name="relay" target="adder"/>
+        <reference name="cache" target="memcache"/>
+    </component>
+
+    <component name="adder">
+        <implementation.scheme script="adder-test.scm"/>
+        <service name="adder">
+            <t:binding.http uri="adder"/>
+        </service>
+    </component>     
+
 </composite>

Modified: tuscany/sca-cpp/trunk/components/cache/client-test.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/client-test.cpp?rev=1024519&r1=1024518&r2=1024519&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/client-test.cpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/client-test.cpp Wed Oct 20 04:59:43 2010
@@ -37,7 +37,8 @@ namespace tuscany {
 namespace cache {
 
 const string memcacheuri("http://localhost:8090/memcache");
-const string frontcacheuri("http://localhost:8090/frontcache");
+const string datacacheuri("http://localhost:8090/datacache");
+const string memocacheuri("http://localhost:8090/memocache");
 
 bool testCache(const string& uri) {
     http::CURLSession cs("", "", "");
@@ -89,8 +90,22 @@ bool testMemcache() {
     return testCache(memcacheuri);
 }
 
-bool testFrontcache() {
-    return testCache(frontcacheuri);
+bool testDatacache() {
+    return testCache(datacacheuri);
+}
+
+bool testMemocache() {
+    http::CURLSession cs("", "", "");
+
+    const failable<value> res = http::evalExpr(mklist<value>(string("add"), 33, 22), memocacheuri, cs);
+    assert(hasContent(res));
+    assert((int)content(res) == 55);
+
+    const failable<value> res2 = http::evalExpr(mklist<value>(string("add"), 33, 22), memocacheuri, cs);
+    assert(hasContent(res2));
+    assert((int)content(res2) == 55);
+
+    return true;
 }
 
 struct getLoop {
@@ -131,7 +146,8 @@ int main() {
     tuscany::cout << "Testing..." << tuscany::endl;
 
     tuscany::cache::testMemcache();
-    tuscany::cache::testFrontcache();
+    tuscany::cache::testDatacache();
+    tuscany::cache::testMemocache();
     tuscany::cache::testGetPerf();
 
     tuscany::cout << "OK" << tuscany::endl;

Copied: tuscany/sca-cpp/trunk/components/cache/datacache.cpp (from r999229, tuscany/sca-cpp/trunk/components/cache/frontcache.cpp)
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/datacache.cpp?p2=tuscany/sca-cpp/trunk/components/cache/datacache.cpp&p1=tuscany/sca-cpp/trunk/components/cache/frontcache.cpp&r1=999229&r2=1024519&rev=1024519&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/frontcache.cpp (original)
+++ tuscany/sca-cpp/trunk/components/cache/datacache.cpp Wed Oct 20 04:59:43 2010
@@ -20,14 +20,14 @@
 /* $Rev$ $Date$ */
 
 /**
- * A front cache component implementation which coordinates access to two
+ * A data cache component implementation which coordinates access to two
  * levels of backend read/write caches or stores. Each cache or store is
  * accessed through two references: a writer reference and a reader reference.
  *
  * This is useful if your level2 store is made of a master and slave
  * replicated databases, you can then wire the writer reference to the master
  * database and the reader reference to one your slave databases (assuming
- * that the updates eventually get replicated to the slave database,in the
+ * that the updates eventually get replicated to the slave database, in the
  * meantime the updates will be retrieved from the level1 cache).
  */
 
@@ -38,7 +38,7 @@
 #include "monad.hpp"
 
 namespace tuscany {
-namespace frontcache {
+namespace datacache {
 
 /**
  * Get an item from the cache.
@@ -112,13 +112,13 @@ extern "C" {
 const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
     const tuscany::value func(car(params));
     if (func == "get")
-        return tuscany::frontcache::get(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params));
+        return tuscany::datacache::get(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params));
     if (func == "post")
-        return tuscany::frontcache::post(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params), caddddddr(params));
+        return tuscany::datacache::post(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params), caddddddr(params));
     if (func == "put")
-        return tuscany::frontcache::put(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params), caddddddr(params));
+        return tuscany::datacache::put(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params), caddddddr(params));
     if (func == "delete")
-        return tuscany::frontcache::del(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params));
+        return tuscany::datacache::del(cadr(params), caddr(params), cadddr(params), caddddr(params), cadddddr(params));
     return tuscany::mkfailure<tuscany::value>();
 }
 

Added: tuscany/sca-cpp/trunk/components/cache/memocache.cpp
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/memocache.cpp?rev=1024519&view=auto
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/memocache.cpp (added)
+++ tuscany/sca-cpp/trunk/components/cache/memocache.cpp Wed Oct 20 04:59:43 2010
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/* $Rev$ $Date$ */
+
+/**
+ * A cache component implementation which memoizes the value of function
+ * applications, keyed by the function arguments, in a key/value cache passed
+ * as a reference.
+ *
+ * This is useful if your functions are idempotent and applied many times to
+ * the same arguments. The results can then be retrieved quickly from the
+ * cache without actually applying the function.
+ */
+
+#include "string.hpp"
+#include "function.hpp"
+#include "list.hpp"
+#include "value.hpp"
+#include "monad.hpp"
+
+namespace tuscany {
+namespace memocache {
+
+/**
+ * Memoize the value of a function application in a cache.
+ */
+const failable<value> memoize(const list<value>& params, const lambda<value(const list<value>&)> relay, const lambda<value(const list<value>&)> cache) {
+    debug(params, "memocache::memoize::params");
+
+    // Lookup memoized value from cache
+    const value val = cache(mklist<value>("get", params));
+    if (!isNil(val)) {
+        debug(val, "memocache::memoize::cached");
+        return val;
+    }
+
+    // Apply the given function
+    const value res = relay(params);
+    debug(res, "memocache::memoize::res");
+
+    // Store the result value in the cache
+    cache(mklist<value>("put", params, res));
+
+    return res;
+}
+
+}
+}
+
+extern "C" {
+
+const tuscany::value apply(const tuscany::list<tuscany::value>& params) {
+    const tuscany::value func(car(params));
+    if (func == "start" || func == "stop")
+        return tuscany::mkfailure<tuscany::value>();
+    const tuscany::list<tuscany::value> rev = tuscany::reverse(params);
+    return tuscany::memocache::memoize(tuscany::reverse(tuscany::cddr(rev)), tuscany::cadr(rev), tuscany::car(rev));
+}
+
+}

Modified: tuscany/sca-cpp/trunk/components/cache/server-test
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/components/cache/server-test?rev=1024519&r1=1024518&r2=1024519&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/components/cache/server-test (original)
+++ tuscany/sca-cpp/trunk/components/cache/server-test Wed Oct 20 04:59:43 2010
@@ -23,7 +23,7 @@
 ../../modules/server/scheme-conf tmp
 cat >>tmp/conf/httpd.conf <<EOF
 SCAContribution `pwd`/
-SCAComposite memcache.composite
+SCAComposite cache.composite
 EOF
 
 ./memcached-start 11211

Modified: tuscany/sca-cpp/trunk/samples/store-cluster/shared/shared.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-cluster/shared/shared.composite?rev=1024519&r1=1024518&r2=1024519&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-cluster/shared/shared.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-cluster/shared/shared.composite Wed Oct 20 04:59:43 2010
@@ -23,7 +23,7 @@
   name="shared">
         
     <component name="Cache">
-        <implementation.cpp path="../../../components/cache" library="libfrontcache"/>
+        <implementation.cpp path="../../../components/cache" library="libdatacache"/>
         <service name="Cache">
             <t:binding.atom uri="cache"/>
         </service>

Modified: tuscany/sca-cpp/trunk/samples/store-sql/store.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-cpp/trunk/samples/store-sql/store.composite?rev=1024519&r1=1024518&r2=1024519&view=diff
==============================================================================
--- tuscany/sca-cpp/trunk/samples/store-sql/store.composite (original)
+++ tuscany/sca-cpp/trunk/samples/store-sql/store.composite Wed Oct 20 04:59:43 2010
@@ -60,7 +60,7 @@
     </component>     
 
     <component name="Cache">
-        <implementation.cpp path="../../components/cache" library="libfrontcache"/>
+        <implementation.cpp path="../../components/cache" library="libdatacache"/>
         <service name="Cache">
             <t:binding.atom uri="cache"/>
         </service>