summaryrefslogtreecommitdiffstats
path: root/sca-cpp/trunk/components/cache/memcache.hpp
diff options
context:
space:
mode:
authorjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2013-01-03 07:41:14 +0000
committerjsdelfino <jsdelfino@13f79535-47bb-0310-9956-ffa450edef68>2013-01-03 07:41:14 +0000
commit9e1b9e73145e00ea591bd1e0e9777625bad66dc9 (patch)
treec6563988970251cba763364bcddd33ac7fe23970 /sca-cpp/trunk/components/cache/memcache.hpp
parent157ca678dee75e7881a0198425d0c8328f0bee04 (diff)
Add support for HTTP patch and application of patch scripts to server and data store components.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1428192 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-cpp/trunk/components/cache/memcache.hpp')
-rw-r--r--sca-cpp/trunk/components/cache/memcache.hpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/sca-cpp/trunk/components/cache/memcache.hpp b/sca-cpp/trunk/components/cache/memcache.hpp
index 00ee9c6291..7962d1caa0 100644
--- a/sca-cpp/trunk/components/cache/memcache.hpp
+++ b/sca-cpp/trunk/components/cache/memcache.hpp
@@ -73,6 +73,7 @@ private:
friend const failable<bool> post(const value& key, const value& val, const MemCached& cache);
friend const failable<bool> put(const value& key, const value& val, const MemCached& cache);
+ friend const failable<bool> patch(const value& key, const value& val, const MemCached& cache);
friend const failable<value> get(const value& key, const MemCached& cache);
friend const failable<bool> del(const value& key, const MemCached& cache);
@@ -177,6 +178,26 @@ const failable<bool> put(const value& key, const value& val, const MemCached& ca
}
/**
+ * Patch an item in the cache. If the item doesn't exist it is added.
+ */
+const failable<bool> patch(const value& key, const value& val, const MemCached& cache) {
+ debug(key, "memcache::patch::key");
+ debug(val, "memcache::patch::value");
+
+ const string ks(write(content(scheme::writeValue(key))));
+ const string vs(write(content(scheme::writeValue(val))));
+ const apr_status_t rc = apr_memcache_set(cache.mc, nospaces(c_str(ks)), const_cast<char*>(c_str(vs)), length(vs), 0, 27);
+ if (rc != APR_SUCCESS) {
+ ostringstream os;
+ os << "Couldn't set memcached entry: " << key;
+ return mkfailure<bool>(str(os));
+ }
+
+ debug(true, "memcache::patch::result");
+ return true;
+}
+
+/**
* Get an item from the cache.
*/
const failable<value> get(const value& key, const MemCached& cache) {
@@ -209,7 +230,7 @@ const failable<bool> del(const value& key, const MemCached& cache) {
if (rc != APR_SUCCESS) {
ostringstream os;
os << "Couldn't delete memcached entry: " << key;
- return mkfailure<bool>(str(os));
+ return rc == APR_NOTFOUND? mkfailure<bool>(str(os), 404, false) : mkfailure<bool>(str(os));
}
debug(true, "memcache::delete::result");