You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@guacamole.apache.org by mj...@apache.org on 2016/03/20 03:22:10 UTC

[30/50] incubator-guacamole-client git commit: GUAC-1378: Evict cache of $templateRequest results when $templateCache is modified externally.

GUAC-1378: Evict cache of $templateRequest results when $templateCache is modified externally.

Project: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/commit/c01e8c6a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/tree/c01e8c6a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/diff/c01e8c6a

Branch: refs/heads/master
Commit: c01e8c6a9a6037295272353910ad11bc0bff1562
Parents: 8f17e9e
Author: Michael Jumper <mi...@guac-dev.org>
Authored: Thu Feb 18 19:52:44 2016 -0800
Committer: Michael Jumper <mi...@guac-dev.org>
Committed: Thu Feb 18 19:56:21 2016 -0800

----------------------------------------------------------------------
 .../index/config/templateRequestDecorator.js    | 64 ++++++++++++++++----
 1 file changed, 53 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-guacamole-client/blob/c01e8c6a/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
----------------------------------------------------------------------
diff --git a/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js b/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
index 43655bc..07b669b 100644
--- a/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
+++ b/guacamole/src/main/webapp/app/index/config/templateRequestDecorator.js
@@ -22,24 +22,66 @@
 
 /**
  * Overrides $templateRequest such that HTML patches defined within Guacamole
- * extensions are automatically applied to template contents.
+ * extensions are automatically applied to template contents. As the results of
+ * $templateRequest are cached internally, $templateCache is also overridden to
+ * update the internal cache as necessary.
  */
 angular.module('index').config(['$provide', function($provide) {
-    $provide.decorator('$templateRequest', ['$delegate', '$injector',
-            function decorateTemplateRequest($delegate, $injector) {
 
-        // Required services
-        var $q = $injector.get('$q');
+    /**
+     * A map of previously-returned promises from past calls to
+     * $templateRequest(). Future calls to $templateRequest() will return
+     * new promises chained to the first promise returned for a given URL,
+     * rather than redo patch processing for every request.
+     *
+     * @type Object.<String, Promise.<String>>
+     */
+    var promiseCache = {};
+
+    // Decorate $templateCache such that promiseCache is updated if a template
+    // is modified within $templateCache at runtime
+    $provide.decorator('$templateCache', ['$delegate',
+            function decorateTemplateCache($delegate) {
+
+        // Create shallow copy of original $templateCache which we can safely
+        // override
+        var decoratedTemplateCache = angular.extend({}, $delegate);
 
         /**
-         * A map of previously-returned promises from past calls to
-         * $templateRequest(). Future calls to $templateRequest() will return
-         * new promises chained to the first promise returned for a given URL,
-         * rather than redo patch processing for every request.
+         * Overridden version of $templateCache.put() which automatically
+         * invalidates the cached $templateRequest result when used. Only the
+         * URL parameter is defined, as all other arguments, if any, will be
+         * passed through to the original $templateCache.put() when the actual
+         * put() operation is performed.
+         *
+         * @param {String} url
+         *     The URL of the template whose entry is being updated.
          *
-         * @type Object.<String, Promise.<String>>
+         * @return {Object}
+         *     The value returned by $templateCache.put(), which is defined as
+         *     being the value that was just stored at the provided URL.
          */
-        var promiseCache = {};
+        decoratedTemplateCache.put = function put(url) {
+
+            // Evict old cached $templateRequest() result
+            delete promiseCache[url];
+
+            // Continue with originally-requested put() operation
+            return $delegate.put.apply(this, arguments);
+
+        };
+
+        return decoratedTemplateCache;
+
+    }]);
+
+    // Decorate $templateRequest such that it automatically applies any HTML
+    // patches associated with installed Guacamole extensions
+    $provide.decorator('$templateRequest', ['$delegate', '$injector',
+            function decorateTemplateRequest($delegate, $injector) {
+
+        // Required services
+        var $q = $injector.get('$q');
 
         /**
          * Array of the raw HTML of all patches which should be applied to the