Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8704411
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:05:58+00:00 2026-06-13T03:05:58+00:00

I would like my Spring Controller to cache the content which returns. I have

  • 0

I would like my Spring Controller to cache the content which returns. I have found a lot of questions how to disable caching. I would like to know how to enable caching. My Controller looks like this one:

@Controller
public class SimpleController {

    @RequestMapping("/webpage.htm")
    public ModelAndView webpage(HttpServletRequest request, 
                                HttpServletResponse response) {
        ModelAndView mav = new ModelAndView("webpage");
        httpServletResponse.setHeader(“Cache-Control”, “public”);
        //some code
        return mav;
    }
}

As you can see I have added the line: httpServletResponse.setHeader(“Cache-Control”, “public”); to set caching but in my browser when I refresh this page I am still getting the same status result: 200 OK. How can I achieve result 304 not modified? I can set annotation @ResponseStatus(value = HttpStatus.NOT_MODIFIED) on this method but will it be only status or also actual caching?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T03:06:00+00:00Added an answer on June 13, 2026 at 3:06 am

    Quoting 14.9.1 What is Cacheable:

    public – Indicates that the response MAY be cached by any cache, even if it would normally be non-cacheable or cacheable only within a non- shared cache.

    Basically the Cache-Control: public is not enough, it only asks the browser to cache normally not cached resources, e.g. over HTTPS.

    Caching in HTTP is actually quite complex and it involves several other headers:

    • Cache-Control – discussed above

    • Expires – when given resource should be considered stale

    • Last-Modified – when was resource last modified

    • ETag – unique tag of resource, changed in every revision

    • Vary – separate caching based on different headers

    • If-Modified-Since, If-None-Match, …

    I found Caching Tutorial to be pretty comprehensive. Not all headers are meant to be used together and you have to be really sure what you are doing. Thus I recommend using built-in solutions like EhCache web caching.

    Also it’s not a good idea to pollute your controller with such low-level details.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller ActionResult that returns JSON that I would like to cache.
I have a Spring MVC controller and when an exception occurs I would like
I have Spring web application. I would like to put some common piece of
I would like to have an item in the ASP.NET CacheObject, which if it
I have a REST web service using spring MVC which is external-facing. I would
I have a controller where I would like to check if a user in
I have started learning GWT and I would like to know if it is
I am new to Spring MVC and would like to know how it handles
I have integrated Spring Security in my application , and would like to display
in a Spring MVC Controller I would like to start a thread that continues

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.