[Asterisk-code-review] res_sorcery_memory_cache: Improve behavior of AMI and CLI object expire. (asterisk[13])

Joshua Colp asteriskteam at digium.com
Wed Jun 10 04:42:15 CDT 2020


Joshua Colp has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/14511 )


Change subject: res_sorcery_memory_cache: Improve behavior of AMI and CLI object expire.
......................................................................

res_sorcery_memory_cache: Improve behavior of AMI and CLI object expire.

The AMI action and CLI command did not take into account the properties
of full backend caching. This resulted in an expired object remaining
removed until a full backend update occurred, instead of having the object
updated when needed.

This change makes it so that the AMI action and CLI command for object
expire are treated as a full cache expire and population when full
backend caching is enabled ensuring the cache represents the backend.

ASTERISK-28942

Change-Id: Id662d888f177ab566c8e802ad583083b742d21f4
---
M res/res_sorcery_memory_cache.c
1 file changed, 18 insertions(+), 4 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/11/14511/1

diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c
index 5029131..1a64c14 100644
--- a/res/res_sorcery_memory_cache.c
+++ b/res/res_sorcery_memory_cache.c
@@ -54,7 +54,9 @@
 			</parameter>
 		</syntax>
 		<description>
-			<para>Expires (removes) an object from a sorcery memory cache.</para>
+			<para>Expires (removes) an object from a sorcery memory cache. If full backend caching is enabled
+			this is treated as a full cache expire and populate instead. It is recommended to use the
+			SorceryMemoryCachePopulate AMI action instead in this case.</para>
 		</description>
 	</manager>
 	<manager name="SorceryMemoryCacheExpire" language="en_US">
@@ -1892,7 +1894,11 @@
 		remove_all_from_cache(cache);
 		ast_cli(a->fd, "All objects have been removed from cache '%s'\n", a->argv[4]);
 	} else {
-		if (!remove_from_cache(cache, a->argv[5], 1)) {
+		if (cache->full_backend_cache) {
+			remove_all_from_cache(cache);
+			memory_cache_populate(cache->sorcery, cache->object_type, cache);
+			ast_cli(a->fd, "Due to full backend caching all objects were expired and repopulated on cache '%s'\n", a->argv[4]);
+		} else if (!remove_from_cache(cache, a->argv[5], 1)) {
 			ast_cli(a->fd, "Successfully expired object '%s' from cache '%s'\n", a->argv[5], a->argv[4]);
 		} else {
 			ast_cli(a->fd, "Object '%s' was not expired from cache '%s' as it was not found\n", a->argv[5],
@@ -2084,12 +2090,20 @@
 	}
 
 	ao2_wrlock(cache->objects);
-	res = remove_from_cache(cache, object_name, 1);
+	if (cache->full_backend_cache) {
+		remove_all_from_cache(cache);
+		memory_cache_populate(cache->sorcery, cache->object_type, cache);
+		res = 1;
+	} else {
+		res = remove_from_cache(cache, object_name, 1);
+	}
 	ao2_unlock(cache->objects);
 
 	ao2_ref(cache, -1);
 
-	if (!res) {
+	if (res == 1) {
+		astman_send_ack(s, m, "Due to full backend caching all objects were expired and repopulated in the cache, consider using SorceryMemoryCachePopulate instead\n");
+	} else if (!res) {
 		astman_send_ack(s, m, "The provided object was expired from the cache\n");
 	} else {
 		astman_send_error(s, m, "The provided object could not be expired from the cache\n");

-- 
To view, visit https://gerrit.asterisk.org/c/asterisk/+/14511
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-Change-Id: Id662d888f177ab566c8e802ad583083b742d21f4
Gerrit-Change-Number: 14511
Gerrit-PatchSet: 1
Gerrit-Owner: Joshua Colp <jcolp at sangoma.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200610/fda29f56/attachment.html>


More information about the asterisk-code-review mailing list