<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">As my understanding all you need is doing a body filter on backend_upstream response and send a set request to memcache with value is response itself. <div><br></div><div>To determine whether response is from memcache or from backend, before proxy pass request to backend you can set some customize header like x-update-cache: true, inside the filter you check that header and perform set operation. <br><br><div id="AppleMailSignature" dir="ltr">--<div>Hưng</div></div><div dir="ltr"><br>On Feb 18, 2019, at 21:21, <<a href="mailto:Maciej.Grochowski@sony.com">Maciej.Grochowski@sony.com</a>> <<a href="mailto:Maciej.Grochowski@sony.com">Maciej.Grochowski@sony.com</a>> wrote:<br><br></div><blockquote type="cite"><div dir="ltr">
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
<div class="WordSection1">
<p class="MsoNormal">At very beginning apologizes for the newbie question, but I am very new in Nginx but would like to extend some functionality in the existing module.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am currently using ngx_http_enhanced_memcached_module, and it meets most of my needs.
<o:p></o:p></p>
<p class="MsoNormal">However, currently, I need to manually populate cache, via PUT requests.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">My nginx configuration looks as follow:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal">upstream memcached_upstream {<o:p></o:p></p>
<p class="MsoNormal"> server 127.0.0.1:11211;<o:p></o:p></p>
<p class="MsoNormal"> keepalive 20;<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal">upstream backendstorage_upstream {<o:p></o:p></p>
<p class="MsoNormal"> server 10.0.0.10:9000<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">server {<o:p></o:p></p>
<p class="MsoNormal"> location / {<o:p></o:p></p>
<p class="MsoNormal"> error_page 404 502 504 = @fallback;<o:p></o:p></p>
<p class="MsoNormal"> error_page 405 = 200 $uri;<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> set $enhanced_memcached_key "$request_uri";<o:p></o:p></p>
<p class="MsoNormal"> ...<o:p></o:p></p>
<p class="MsoNormal"> enhanced_memcached_pass memcached_upstream;<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"> location @fallback {<o:p></o:p></p>
<p class="MsoNormal"> proxy_pass <a href="http://backendstorage_upstream">http://backendstorage_upstream</a>;<o:p></o:p></p>
<p class="MsoNormal"> }<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal">```<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I started thinking of embedding STORE functionality inside the module itself. A high-level idea would be:<o:p></o:p></p>
<p class="MsoNormal">whenever we got cache miss to fetch the response from backend_upstream via `proxy_pass` and then get response and
<o:p></o:p></p>
<p class="MsoNormal">sent it back to the `memcached_upstream` via PUT method.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">This sounds really simple, however, I have 2 questions based on my understanding of Nginx internals:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">1. `proxy_pass` is a method which runs inside NGX_HTTP_CONTENT_PHASE, so based on documentation only one method in that type can be inside the location.<o:p></o:p></p>
<p class="MsoNormal">In order to hijack response from `proxy_pass`, the only way that I can see is to wrap `proxy_pass` via i.e. `enhanced_memcached_proxy_pass`.
<o:p></o:p></p>
<p class="MsoNormal">In that custom method: first of all original code from proxy module would be run and then as one of the end stages, a custom method like (i.e. input_filter) would be able to access response from the backend and send content to Memcached.<o:p></o:p></p>
<p class="MsoNormal">Given the size of the proxy module and its implementation based on callbacks, first thoughts that I have is that I can end up easily via merging these modules.<o:p></o:p></p>
<p class="MsoNormal">Is there any other easier way to access the response from location?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">2. If I will need to implement such a method like `enhanced_memcached_proxy_pass`, is there any recommended (asynchronous) way to send PUT to external service.<o:p></o:p></p>
<p class="MsoNormal">My understanding is that as long as we spent time doing operations inside pipeline we block particular event which can cause delay to the client (of course here I would like to send response first to the client and then store it).<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thank you for any help!<o:p></o:p></p>
<p class="MsoNormal">Maciej<o:p></o:p></p>
</div>
</div></blockquote><blockquote type="cite"><div dir="ltr"><span>_______________________________________________</span><br><span>nginx-devel mailing list</span><br><span><a href="mailto:nginx-devel@nginx.org">nginx-devel@nginx.org</a></span><br><span><a href="http://mailman.nginx.org/mailman/listinfo/nginx-devel">http://mailman.nginx.org/mailman/listinfo/nginx-devel</a></span></div></blockquote></div></body></html>