Forum Stats

  • 3,840,381 Users
  • 2,262,597 Discussions
  • 7,901,254 Comments

Discussions

Clear user browser cache via code

User_19BPU
User_19BPU Member Posts: 1,086 Blue Ribbon
edited Apr 16, 2019 7:03AM in Java Programming

Hi ,

I need to programmatically clear the user browser cache/cookie/temp files through the Java/J2EE code initially when the user hit the site for any transactions. So that there wont be any cache issue for the user to perform various transactions. Please let me know what is the best approach to do so?

Thanks.

Tagged:
morgalr

Answers

  • morgalr
    morgalr Member Posts: 457
    edited Mar 27, 2019 7:59PM

    I have not found a "good way" to do this, but requesting the browser to do it, is the best I've ever come up with.  The browser knows where it is supporting it's cache.

  • dvohra21
    dvohra21 Member Posts: 14,627 Gold Crown
    edited Apr 7, 2019 8:13PM

    The recommended method is

    <span class="tag" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;"><meta</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="atn" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #e64320;">http-equiv</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">=</span><span class="atv" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #0f74bd;">'cache-control'</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="atn" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #e64320;">content</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">=</span><span class="atv" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #0f74bd;">'no-cache'</span><span class="tag" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">></span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/></span><span class="tag" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;"><meta</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="atn" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #e64320;">http-equiv</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">=</span><span class="atv" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #0f74bd;">'expires'</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="atn" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #e64320;">content</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">=</span><span class="atv" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #0f74bd;">'0'</span><span class="tag" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">></span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"><br/></span><span class="tag" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;"><meta</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="atn" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #e64320;">http-equiv</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">=</span><span class="atv" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #0f74bd;">'pragma'</span><span class="pln" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;"> </span><span class="atn" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #e64320;">content</span><span class="pun" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #303336;">=</span><span class="atv" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #0f74bd;">'no-cache'</span><span class="tag" style="font-style: inherit; font-weight: inherit; font-family: inherit; color: #7d2727;">></span>

  • jwenting
    jwenting Member Posts: 4,864 Gold Badge
    edited Apr 16, 2019 7:03AM

    You won't be able to do that in Java.

    You need to do it through enforcing things like no-cache http headers in the response and meta tags in the html and hope that the browser and any proxy servers in between you and the client honour those headers (of which there is no guarantee).

    morgalr