<div dir="ltr">Let me reiterate the question.<div><br></div><div><div style="font-size:12.8px">By default varnish will not cache if there is cookie present in request or a set-cookie value is there in server response. In the following case we have retained COOKIE1 and |COOKIE2, but can varnish  still caches the responses(I have the unset cookie  from backend responses), by returning hash in vcl recv. No changes in vcl_hash is made, so caching is based on req_url.</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">Please advise on any issues on this approach.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">***************************************</div><div style="font-size:12.8px"><span class="gmail-m_1639037540278786416gmail-n" style="font-size:12.8px;white-space:pre-wrap">sub</span><span style="font-size:12.8px;white-space:pre-wrap"> </span><span class="gmail-m_1639037540278786416gmail-n" style="font-size:12.8px;white-space:pre-wrap">vcl_recv</span><span style="font-size:12.8px;white-space:pre-wrap"> </span><span class="gmail-m_1639037540278786416gmail-p" style="font-size:12.8px;white-space:pre-wrap">{</span><br></div><div style="font-size:12.8px"><pre style="white-space:pre-wrap">    <span class="gmail-m_1639037540278786416gmail-k">if</span> <span class="gmail-m_1639037540278786416gmail-p">(</span><span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span><span class="gmail-m_1639037540278786416gmail-p">)</span> <span class="gmail-m_1639037540278786416gmail-p">{</span>
        <span class="gmail-m_1639037540278786416gmail-nb">set</span> <span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span> <span class="gmail-m_1639037540278786416gmail-o">=</span> <span class="gmail-m_1639037540278786416gmail-s2">";"</span> <span class="gmail-m_1639037540278786416gmail-o">+</span> <span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span><span class="gmail-m_1639037540278786416gmail-p">;</span>
        <span class="gmail-m_1639037540278786416gmail-nb">set</span> <span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span> <span class="gmail-m_1639037540278786416gmail-o">=</span> <span class="gmail-m_1639037540278786416gmail-n">regsuball</span><span class="gmail-m_1639037540278786416gmail-p">(</span><span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">"; +"</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">";"</span><span class="gmail-m_1639037540278786416gmail-p">);</span>
        <span class="gmail-m_1639037540278786416gmail-nb">set</span> <span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span> <span class="gmail-m_1639037540278786416gmail-o">=</span> <span class="gmail-m_1639037540278786416gmail-n">regsuball</span><span class="gmail-m_1639037540278786416gmail-p">(</span><span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">";(COOKIE1|COOKIE2)="</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">"; </span><span class="gmail-m_1639037540278786416gmail-se">\1</span><span class="gmail-m_1639037540278786416gmail-s2">="</span><span class="gmail-m_1639037540278786416gmail-p">);</span>
        <span class="gmail-m_1639037540278786416gmail-nb">set</span> <span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span> <span class="gmail-m_1639037540278786416gmail-o">=</span> <span class="gmail-m_1639037540278786416gmail-n">regsuball</span><span class="gmail-m_1639037540278786416gmail-p">(</span><span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">";[^ ][^;]*"</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">""</span><span class="gmail-m_1639037540278786416gmail-p">);</span>
        <span class="gmail-m_1639037540278786416gmail-nb">set</span> <span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span> <span class="gmail-m_1639037540278786416gmail-o">=</span> <span class="gmail-m_1639037540278786416gmail-n">regsuball</span><span class="gmail-m_1639037540278786416gmail-p">(</span><span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">"^[; ]+|[; ]+$"</span><span class="gmail-m_1639037540278786416gmail-p">,</span> <span class="gmail-m_1639037540278786416gmail-s2">""</span><span class="gmail-m_1639037540278786416gmail-p">);</span>

        <span class="gmail-m_1639037540278786416gmail-k">if</span> <span class="gmail-m_1639037540278786416gmail-p">(</span><span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span> <span class="gmail-m_1639037540278786416gmail-o">==</span> <span class="gmail-m_1639037540278786416gmail-s2">""</span><span class="gmail-m_1639037540278786416gmail-p">)</span> <span class="gmail-m_1639037540278786416gmail-p">{</span>
            <span class="gmail-m_1639037540278786416gmail-n">unset</span> <span class="gmail-m_1639037540278786416gmail-n">req</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">http</span><span class="gmail-m_1639037540278786416gmail-o">.</span><span class="gmail-m_1639037540278786416gmail-n">Cookie</span><span class="gmail-m_1639037540278786416gmail-p">;</span></pre><pre style="white-space:pre-wrap">            return(pass) 
        <span class="gmail-m_1639037540278786416gmail-p">}</span>
      return(hash)</pre><pre style="white-space:pre-wrap"><span class="gmail-m_1639037540278786416gmail-p">     }</span>
<span class="gmail-m_1639037540278786416gmail-p">}</span></pre><pre style="white-space:pre-wrap"><span class="gmail-m_1639037540278786416gmail-p"><span style="font-family:arial,sans-serif;font-size:12.8px;white-space:normal">***************************************</span><br></span></pre><pre style="white-space:pre-wrap"><span class="gmail-m_1639037540278786416gmail-p"><br class="gmail-m_1639037540278786416gmail-Apple-interchange-newline"></span></pre></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, May 29, 2017 at 9:45 PM, sreeranj s <span dir="ltr"><<a href="mailto:sreeranj4droid@gmail.com" target="_blank">sreeranj4droid@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>As per the link <a href="https://varnish-cache.org/docs/4.0/users-guide/increasing-your-hitrate.html" target="_blank">https://varnish-cache.org/<wbr>docs/4.0/users-guide/<wbr>increasing-your-hitrate.html</a>, following code will help us to retain COOKIE1 and |COOKIE2, but strip other cookies. So COOKIE1 and |COOKIE2 is send to backend. I have the following questions.<br></div><div><br></div><div>1) By default varnish will not cache if there is cookie present in request or a set-cookie value is there in server response. In the following case we have retained COOKIE1 and |COOKIE2, but I still have varnish caches the responses(I have the unset cookie  from backend responses). Could you please let me know the reason. </div><div><br></div><div>2) If the approach is ok, please advise on any issues are related to this approach.</div><div><br></div><div>3) I am not adding any specific value in hash block, so requests are cached only based on req-url or IP. hope that is right.<br></div><div><br></div><div><br></div><div>==============================<wbr>===</div><div><pre><span class="m_1639037540278786416gmail-n">sub</span> <span class="m_1639037540278786416gmail-n">vcl_recv</span> <span class="m_1639037540278786416gmail-p">{</span>
    <span class="m_1639037540278786416gmail-k">if</span> <span class="m_1639037540278786416gmail-p">(</span><span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span><span class="m_1639037540278786416gmail-p">)</span> <span class="m_1639037540278786416gmail-p">{</span>
        <span class="m_1639037540278786416gmail-nb">set</span> <span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span> <span class="m_1639037540278786416gmail-o">=</span> <span class="m_1639037540278786416gmail-s2">";"</span> <span class="m_1639037540278786416gmail-o">+</span> <span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span><span class="m_1639037540278786416gmail-p">;</span>
        <span class="m_1639037540278786416gmail-nb">set</span> <span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span> <span class="m_1639037540278786416gmail-o">=</span> <span class="m_1639037540278786416gmail-n">regsuball</span><span class="m_1639037540278786416gmail-p">(</span><span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">"; +"</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">";"</span><span class="m_1639037540278786416gmail-p">);</span>
        <span class="m_1639037540278786416gmail-nb">set</span> <span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span> <span class="m_1639037540278786416gmail-o">=</span> <span class="m_1639037540278786416gmail-n">regsuball</span><span class="m_1639037540278786416gmail-p">(</span><span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">";(COOKIE1|COOKIE2)="</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">"; </span><span class="m_1639037540278786416gmail-se">\1</span><span class="m_1639037540278786416gmail-s2">="</span><span class="m_1639037540278786416gmail-p">);</span>
        <span class="m_1639037540278786416gmail-nb">set</span> <span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span> <span class="m_1639037540278786416gmail-o">=</span> <span class="m_1639037540278786416gmail-n">regsuball</span><span class="m_1639037540278786416gmail-p">(</span><span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">";[^ ][^;]*"</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">""</span><span class="m_1639037540278786416gmail-p">);</span>
        <span class="m_1639037540278786416gmail-nb">set</span> <span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span> <span class="m_1639037540278786416gmail-o">=</span> <span class="m_1639037540278786416gmail-n">regsuball</span><span class="m_1639037540278786416gmail-p">(</span><span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">"^[; ]+|[; ]+$"</span><span class="m_1639037540278786416gmail-p">,</span> <span class="m_1639037540278786416gmail-s2">""</span><span class="m_1639037540278786416gmail-p">);</span>

        <span class="m_1639037540278786416gmail-k">if</span> <span class="m_1639037540278786416gmail-p">(</span><span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span> <span class="m_1639037540278786416gmail-o">==</span> <span class="m_1639037540278786416gmail-s2">""</span><span class="m_1639037540278786416gmail-p">)</span> <span class="m_1639037540278786416gmail-p">{</span>
            <span class="m_1639037540278786416gmail-n">unset</span> <span class="m_1639037540278786416gmail-n">req</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">http</span><span class="m_1639037540278786416gmail-o">.</span><span class="m_1639037540278786416gmail-n">Cookie</span><span class="m_1639037540278786416gmail-p">;</span>
        <span class="m_1639037540278786416gmail-p">}</span>
    <span class="m_1639037540278786416gmail-p">}</span>
<span class="m_1639037540278786416gmail-p">}</span></pre><pre><span class="m_1639037540278786416gmail-p"><br class="m_1639037540278786416gmail-Apple-interchange-newline"><span style="font-family:arial,sans-serif;white-space:normal">==============================<wbr>===</span><br></span></pre></div></div>
</blockquote></div><br></div>