You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ro...@apache.org on 2017/10/18 23:23:20 UTC

[sling-org-apache-sling-commons-cache-api] 01/07: SLING-2555 moving into the right place this time, sorry.

This is an automated email from the ASF dual-hosted git repository.

rombert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-commons-cache-api.git

commit 5dc76acbba72f2ab25b5001697a1c978fe7e6246
Author: Ian Boston <ie...@apache.org>
AuthorDate: Fri Nov 9 05:22:15 2012 +0000

    SLING-2555 moving into the right place this time, sorry.
    
    
    git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1407364 13f79535-47bb-0310-9956-ffa450edef68
---
 README.txt                                         | 12 +++
 pom.xml                                            | 69 ++++++++++++++++
 .../org/apache/sling/commons/cache/api/Cache.java  | 92 ++++++++++++++++++++++
 .../commons/cache/api/CacheManagerService.java     | 51 ++++++++++++
 .../apache/sling/commons/cache/api/CacheScope.java | 50 ++++++++++++
 .../sling/commons/cache/api/ThreadBound.java       | 35 ++++++++
 .../sling/commons/cache/api/package-info.java      | 24 ++++++
 7 files changed, 333 insertions(+)

diff --git a/README.txt b/README.txt
new file mode 100644
index 0000000..609a1a1
--- /dev/null
+++ b/README.txt
@@ -0,0 +1,12 @@
+Commons Cache.
+
+This is an Cache API, the implementation of which will allow applications written in Sling to cache data locally, 
+cache locally with cluster wide invalidation, and cache and replicate data. The exact nature of the cache behaviour
+depends on the implementation of the API.
+
+
+Acknowledgments
+
+This code was based on a module from Sparse Content Map 29 September 2012 (git:sha1:a222df1937434ad3f07bf6c4f60b19524a158bcb), which itself was based on a snapshot of a 
+module in Sakai Nakamura 27 Jan 2011 (git:sha1:b9d8e65b733ec7c35a3d194c9a5dc12acf13cb34). All know contributors to code in this module have been
+contacted for permission to grant license to the Apache Foundation.
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..fe26b37
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,69 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+    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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.sling</groupId>
+        <artifactId>sling</artifactId>
+        <version>13</version>
+    </parent>
+
+    <artifactId>org.apache.sling.commons.cache.api</artifactId>
+    <version>0.1-SNAPSHOT</version>
+    <packaging>bundle</packaging>
+
+    <name>Apache Sling Cache API</name>
+    <description>
+        This bundle porvides a Cache API for Sling applications to use.
+    </description>
+
+    <scm>
+        <connection>scm:svn:http://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/api</connection>
+        <developerConnection>scm:svn:https://svn.apache.org/repos/asf/sling/whiteboard/ieb/cache/api</developerConnection>
+        <url>http://svn.apache.org/viewvc/sling/whiteboard/ieb/cache/api</url>
+    </scm>
+    
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.3.6</version>
+                <extensions>true</extensions>
+                <configuration>
+                    <instructions>
+                    </instructions>
+                </configuration>
+            </plugin>
+        </plugins>
+    </build>
+
+    <dependencies>
+        <!--  used for package-info annotations -->
+        <dependency>
+            <groupId>biz.aQute</groupId>
+            <artifactId>bndlib</artifactId>
+            <version>1.50.0</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git a/src/main/java/org/apache/sling/commons/cache/api/Cache.java b/src/main/java/org/apache/sling/commons/cache/api/Cache.java
new file mode 100644
index 0000000..20f1488
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/cache/api/Cache.java
@@ -0,0 +1,92 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.commons.cache.api;
+
+import java.util.Collection;
+
+/**
+ * A Cache managed by the cache manager.
+ */
+public interface Cache<V> {
+
+	/**
+	 * Cache an object
+	 * 
+	 * @param key
+	 *            The key with which to find the object.
+	 * @param payload
+	 *            The object to cache.
+	 * @param duration
+	 *            The time to cache the object (seconds).
+	 */
+	V put(String key, V payload);
+
+	/**
+	 * Test for a non expired entry in the cache.
+	 * 
+	 * @param key
+	 *            The cache key.
+	 * @return true if the key maps to a non-expired cache entry, false if not.
+	 */
+	boolean containsKey(String key);
+
+	/**
+	 * Get the non expired entry, or null if not there (or expired)
+	 * 
+	 * @param key
+	 *            The cache key.
+	 * @return The payload, or null if the payload is null, the key is not
+	 *         found, or the entry has expired (Note: use containsKey() to
+	 *         remove this ambiguity).
+	 */
+	V get(String key);
+
+	/**
+	 * Clear all entries.
+	 */
+	void clear();
+
+	/**
+	 * Remove this entry from the cache.
+	 * 
+	 * @param key
+	 *            The cache key.
+	 */
+	boolean remove(String key);
+
+	/**
+	 * Remove the key and any child keys from the cache, this is an expensive
+	 * operation.
+	 * 
+	 * @param key
+	 */
+	void removeChildren(String key);
+
+	/**
+	 * @return
+	 */
+	Collection<V> values();
+
+	/**
+	 * @return
+	 */
+	Collection<String> keys();
+
+}
diff --git a/src/main/java/org/apache/sling/commons/cache/api/CacheManagerService.java b/src/main/java/org/apache/sling/commons/cache/api/CacheManagerService.java
new file mode 100644
index 0000000..b40a510
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/cache/api/CacheManagerService.java
@@ -0,0 +1,51 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.commons.cache.api;
+
+/**
+ * The Cache manager provides access to all caches in the system. Caches are
+ * scoped by CacheScope and those that are bound can be unbound.
+ */
+public interface CacheManagerService {
+
+	/**
+	 * Get a cache to contain a specified type, with a defined scope. Getting a
+	 * cache of the same name in the same scope will return the same cache for
+	 * that scope. The thread invoking the method forms part of the scope for
+	 * CacheScopes THREAD or REQUEST.
+	 * 
+	 * @param <T>
+	 *            The type of the elements, but be serializable for any non
+	 *            thread bound cache.
+	 * @param name
+	 *            the name of the cache.
+	 * @param scope
+	 *            the scope of the cache.
+	 * @return the cache suitable for holding the type T
+	 */
+	<T> Cache<T> getCache(String name, CacheScope scope);
+
+	/**
+	 * Unbind the the context specified in scope.
+	 * 
+	 * @param scope
+	 */
+	void unbind(CacheScope scope);
+}
diff --git a/src/main/java/org/apache/sling/commons/cache/api/CacheScope.java b/src/main/java/org/apache/sling/commons/cache/api/CacheScope.java
new file mode 100644
index 0000000..7040431
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/cache/api/CacheScope.java
@@ -0,0 +1,50 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.commons.cache.api;
+
+/**
+ * Defines the scope of the cache
+ */
+public enum CacheScope {
+	/**
+	 * Bind the Cache to the request scope.
+	 */
+	REQUEST(),
+	/**
+	 * Bind a cache to the Thread, forever. WARNING: use with extreme caution,
+	 * as any classes referenced in this type of cache will keep classloaders
+	 * open and result in memory leaks
+	 */
+	THREAD(),
+	/**
+	 * Bind the cache to the instance, one per instance.
+	 */
+	INSTANCE(),
+	/**
+	 * Make the cache bound to the instance, but accept cluster wide
+	 * invalidations.
+	 */
+	CLUSTERINVALIDATED(),
+	/**
+	 * Replicate the cache over the whole cluster.
+	 */
+	CLUSTERREPLICATED();
+
+}
diff --git a/src/main/java/org/apache/sling/commons/cache/api/ThreadBound.java b/src/main/java/org/apache/sling/commons/cache/api/ThreadBound.java
new file mode 100644
index 0000000..13fe116
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/cache/api/ThreadBound.java
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+package org.apache.sling.commons.cache.api;
+
+/**
+ * Objects that are added to a ThreadLocalManager, that implement this method
+ * will have the unbind method called when the object is ejected from the thread
+ * local.
+ * 
+ */
+public interface ThreadBound {
+
+	/**
+	 * Invoked when the item is unbound from the thread.
+	 */
+	void unbind();
+
+}
diff --git a/src/main/java/org/apache/sling/commons/cache/api/package-info.java b/src/main/java/org/apache/sling/commons/cache/api/package-info.java
new file mode 100644
index 0000000..e853d9c
--- /dev/null
+++ b/src/main/java/org/apache/sling/commons/cache/api/package-info.java
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+@Version("1.0")
+package org.apache.sling.commons.cache.api;
+
+import aQute.bnd.annotation.Version;
+

-- 
To stop receiving notification emails like this one, please contact
"commits@sling.apache.org" <co...@sling.apache.org>.