Overview
Features
Download
Documentation
Community
Add-Ons & Services

Http 1.1 Caching support

Please post support and help requests here.

Http 1.1 Caching support

Postby devdavid » 12 Apr 2013, 06:44

Hi, I wonder whetter the support for http 1.1 response caching is included in POCO/Net.

I would like to use some conditional caching, ie. if a file on the server is updated, my client's poco http request should get the new version, otherwise it should fetch it from disk cache. Below is my code for fetching data, does something need to be added to enable persistent caching?

Best Regards David

Code: Select all
int NetPoco::getJson(string url){

   try
     {
      printnet("Prepare session");

       // prepare session
       URI uri("http://www.google.se");
       HTTPClientSession session(uri.getHost(), uri.getPort());

       // prepare path
      printnet("Prepare path");

       string path(uri.getPathAndQuery());
       if (path.empty()) path = "/";

       // send request
      printnet("Prepare request for");
      printnet(path.c_str());
       HTTPRequest req(HTTPRequest::HTTP_GET, path, HTTPMessage::HTTP_1_1);
       session.sendRequest(req);

       // get response
      printnet("Get response");

       HTTPResponse res;
       cout << res.getStatus() << " " << res.getReason() << endl;

       // print response
      printnet("Print response");

       istream &is = session.receiveResponse(res);
       //StreamCopier::copyStream(is, cout);
       std::stringstream ss;
       //ss<<&is;
       StreamCopier::copyStream(is,ss);
       printnet(ss.str().c_str());

     }
     catch (Exception &ex)
     {
      printnet(ex.displayText().c_str());
       return -1;
     }

     return 0;
   }




(UPDATE)
So part of the answer is here:
http://stackoverflow.com/questions/15965888/c-networking-library-supporting-response-caching

To move on and make an own strategy for this caching i think i need to get expires from the cache headers and cross check with cached values (please tell me if im wrong). So how can i extract the cache header from httpResponse?

Best regards!
devdavid
 
Posts: 17
Joined: 11 Mar 2013, 16:10

Return to Support

Who is online

Users browsing this forum: No registered users and 3 guests

cron