You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by ra...@apache.org on 2015/08/10 12:02:16 UTC
svn commit: r1695008 -
/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
Author: radu
Date: Mon Aug 10 10:02:16 2015
New Revision: 1695008
URL: http://svn.apache.org/r1695008
Log:
SLING-4936 - Enhance the Sling Script Cache to only cache scripts from the search paths
* made ScriptCacheImpl#putScript to only accept scripts from the search paths
Modified:
sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java?rev=1695008&r1=1695007&r2=1695008&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java (original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/impl/ScriptCacheImpl.java Mon Aug 10 10:02:16 2015
@@ -109,6 +109,7 @@ public class ScriptCacheImpl implements
private ServiceRegistration eventHandlerServiceRegistration = null;
private Set<String> extensions = new HashSet<String>();
private String[] additionalExtensions = new String[]{};
+ private String[] searchPaths = {};
// use a static policy so that we can reconfigure the watched script files if the search paths are changed
@Reference(policy = ReferencePolicy.STATIC)
@@ -141,10 +142,15 @@ public class ScriptCacheImpl implements
@Override
public void putScript(CachedScript script) {
- SoftReference<CachedScript> reference = new SoftReference<CachedScript>(script);
writeLock.lock();
try {
- internalMap.put(script.getScriptPath(), reference);
+ for (String searchPath : searchPaths) {
+ if (script.getScriptPath().startsWith(searchPath)) {
+ SoftReference<CachedScript> reference = new SoftReference<CachedScript>(script);
+ internalMap.put(script.getScriptPath(), reference);
+ break;
+ }
+ }
} finally {
writeLock.unlock();
}
@@ -222,6 +228,17 @@ public class ScriptCacheImpl implements
newMap.putAll(internalMap);
internalMap = newMap;
}
+ ResourceResolver resolver = null;
+ try {
+ resolver = rrf.getAdministrativeResourceResolver(null);
+ searchPaths = resolver.getSearchPath();
+ } catch (LoginException e) {
+ LOGGER.error("Unable to store search paths.", e);
+ } finally {
+ if (resolver != null) {
+ resolver.close();
+ }
+ }
configureCache();
active = true;
}