<p>Joshua Colp has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14511">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_sorcery_memory_cache: Improve behavior of AMI and CLI object expire.<br><br>The AMI action and CLI command did not take into account the properties<br>of full backend caching. This resulted in an expired object remaining<br>removed until a full backend update occurred, instead of having the object<br>updated when needed.<br><br>This change makes it so that the AMI action and CLI command for object<br>expire are treated as a full cache expire and population when full<br>backend caching is enabled ensuring the cache represents the backend.<br><br>ASTERISK-28942<br><br>Change-Id: Id662d888f177ab566c8e802ad583083b742d21f4<br>---<br>M res/res_sorcery_memory_cache.c<br>1 file changed, 18 insertions(+), 4 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/11/14511/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_sorcery_memory_cache.c b/res/res_sorcery_memory_cache.c</span><br><span>index 5029131..1a64c14 100644</span><br><span>--- a/res/res_sorcery_memory_cache.c</span><br><span>+++ b/res/res_sorcery_memory_cache.c</span><br><span>@@ -54,7 +54,9 @@</span><br><span>                       </parameter></span><br><span>           </syntax></span><br><span>              <description></span><br><span style="color: hsl(0, 100%, 40%);">-                     <para>Expires (removes) an object from a sorcery memory cache.</para></span><br><span style="color: hsl(120, 100%, 40%);">+                     <para>Expires (removes) an object from a sorcery memory cache. If full backend caching is enabled</span><br><span style="color: hsl(120, 100%, 40%);">+                       this is treated as a full cache expire and populate instead. It is recommended to use the</span><br><span style="color: hsl(120, 100%, 40%);">+                     SorceryMemoryCachePopulate AMI action instead in this case.</para></span><br><span>             </description></span><br><span>         </manager></span><br><span>     <manager name="SorceryMemoryCacheExpire" language="en_US"></span><br><span>@@ -1892,7 +1894,11 @@</span><br><span>                remove_all_from_cache(cache);</span><br><span>                ast_cli(a->fd, "All objects have been removed from cache '%s'\n", a->argv[4]);</span><br><span>       } else {</span><br><span style="color: hsl(0, 100%, 40%);">-                if (!remove_from_cache(cache, a->argv[5], 1)) {</span><br><span style="color: hsl(120, 100%, 40%);">+            if (cache->full_backend_cache) {</span><br><span style="color: hsl(120, 100%, 40%);">+                   remove_all_from_cache(cache);</span><br><span style="color: hsl(120, 100%, 40%);">+                 memory_cache_populate(cache->sorcery, cache->object_type, cache);</span><br><span style="color: hsl(120, 100%, 40%);">+                       ast_cli(a->fd, "Due to full backend caching all objects were expired and repopulated on cache '%s'\n", a->argv[4]);</span><br><span style="color: hsl(120, 100%, 40%);">+           } else if (!remove_from_cache(cache, a->argv[5], 1)) {</span><br><span>                    ast_cli(a->fd, "Successfully expired object '%s' from cache '%s'\n", a->argv[5], a->argv[4]);</span><br><span>             } else {</span><br><span>                     ast_cli(a->fd, "Object '%s' was not expired from cache '%s' as it was not found\n", a->argv[5],</span><br><span>@@ -2084,12 +2090,20 @@</span><br><span>    }</span><br><span> </span><br><span>        ao2_wrlock(cache->objects);</span><br><span style="color: hsl(0, 100%, 40%);">-  res = remove_from_cache(cache, object_name, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+       if (cache->full_backend_cache) {</span><br><span style="color: hsl(120, 100%, 40%);">+           remove_all_from_cache(cache);</span><br><span style="color: hsl(120, 100%, 40%);">+         memory_cache_populate(cache->sorcery, cache->object_type, cache);</span><br><span style="color: hsl(120, 100%, 40%);">+               res = 1;</span><br><span style="color: hsl(120, 100%, 40%);">+      } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              res = remove_from_cache(cache, object_name, 1);</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span>    ao2_unlock(cache->objects);</span><br><span> </span><br><span>   ao2_ref(cache, -1);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">- if (!res) {</span><br><span style="color: hsl(120, 100%, 40%);">+   if (res == 1) {</span><br><span style="color: hsl(120, 100%, 40%);">+               astman_send_ack(s, m, "Due to full backend caching all objects were expired and repopulated in the cache, consider using SorceryMemoryCachePopulate instead\n");</span><br><span style="color: hsl(120, 100%, 40%);">+    } else if (!res) {</span><br><span>           astman_send_ack(s, m, "The provided object was expired from the cache\n");</span><br><span>         } else {</span><br><span>             astman_send_error(s, m, "The provided object could not be expired from the cache\n");</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14511">change 14511</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14511"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-Change-Id: Id662d888f177ab566c8e802ad583083b742d21f4 </div>
<div style="display:none"> Gerrit-Change-Number: 14511 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>