summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBin Yang <bin.yang@windriver.com>2020-03-25 16:19:25 +0800
committerBin Yang <bin.yang@windriver.com>2020-03-25 16:19:25 +0800
commit4317682484a28f10d4590ae9569715dd46f181b3 (patch)
tree47e93084d6a54331bc211785b94aaa6a5bd03671
parented01f456ac1abc0b6ecff90e846d9b54e4172c88 (diff)
Fix issue of unregister cloud region1.5.5
Flush all entries with same prefix to maintain consistency of entries Change-Id: I01b02d7148e16c6a49ad6a13c6fe69382bb9c5f7 Issue-ID: MULTICLOUD-1039 Signed-off-by: Bin Yang <bin.yang@windriver.com>
-rw-r--r--share/common/utils/aai_cache.py26
1 files changed, 21 insertions, 5 deletions
diff --git a/share/common/utils/aai_cache.py b/share/common/utils/aai_cache.py
index c2e8e034..38f10fcd 100644
--- a/share/common/utils/aai_cache.py
+++ b/share/common/utils/aai_cache.py
@@ -1,4 +1,4 @@
-# Copyright (c) 2017-2018 Wind River Systems, Inc.
+# Copyright (c) 2017-2020 Wind River Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -22,7 +22,18 @@ def flush_cache_by_url(resource_url):
try:
# this is to invalidate similar cache data blindly
resource_wo_query = resource_url.split("?", 1)[0]
- cache.delete("AAI_" + resource_wo_query)
+ aaikey = "AAI_" + resource_wo_query
+ cache.delete(aaikey)
+
+ # AAI entry keys: flush all entries with same prefix
+ aaikeylist = json.loads(cache.get("AAIKeys", '[]'))
+ aaikeyset = set([])
+ for k in aaikeylist:
+ if k.find(aaikey) >= 0:
+ cache.delete(k)
+ else:
+ aaikeyset.add(k)
+ cache.set("AAIKeys", json.dumps(list(aaikeyset)))
except:
pass # silently drop any exception
@@ -46,10 +57,15 @@ def set_cache_by_url(resource_url, resource_in_json):
if filter_cache_by_url(resource_url):
# cache the resource for 24 hours
# logger.debug("Cache the resource: "+ resource_url)
- cache.set("AAI_" + resource_url,
- json.dumps(resource_in_json), 3600 * 24)
+ aaikey = "AAI_" + resource_url
+ cache.set(aaikey, json.dumps(resource_in_json), 3600 * 24)
+ # AAI entry keys
+ aaikeylist = json.loads(cache.get("AAIKeys", '[]'))
+ aaikeyset = set(aaikeylist)
+ aaikeyset.add(aaikey)
+ cache.set("AAIKeys", json.dumps(list(aaikeyset)))
except Exception as e:
- logger.error("get_cache_by_url exception: %s" % str(e))
+ logger.error("set_cache_by_url exception: %s" % str(e))
def filter_cache_by_url(resource_url):