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 8980569
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:07:13+00:00 2026-06-15T20:07:13+00:00

I am attempting to confirm URL caching by logging the memory stats around a

  • 0

I am attempting to confirm URL caching by logging the memory stats around a NSURLCache.

I have extended the base NSURLCache as follows:

@implementation  MarksCache : NSURLCache

- (NSCachedURLResponse *) cachedResponseForRequest:(NSURLRequest *)request;
{
    NSString *myString = [request.URL absoluteString];
    DDLogVerbose(@"URL CACHE GET : PRE  : %@ %d %d %d %d", myString,
                 [NSURLCache sharedURLCache].currentDiskUsage ,
                 [NSURLCache sharedURLCache].currentMemoryUsage,
                 [NSURLCache sharedURLCache].diskCapacity,
                 [NSURLCache sharedURLCache].memoryCapacity);

    NSCachedURLResponse *resp = [super cachedResponseForRequest:request];
    //NSURLResponse *rp = [resp response];
    //NSString *rpdesc = [rp description];

    //NSData *data = [resp data];
    //NSString *respdesc = [resp description];
    //NSString *selfdesc = [super description];

    DDLogVerbose(@"URL CACHE GET : POST : %@ %d %d %d %d", myString,
                 [NSURLCache sharedURLCache].currentDiskUsage ,
                 [NSURLCache sharedURLCache].currentMemoryUsage,
                 [NSURLCache sharedURLCache].diskCapacity,
                 [NSURLCache sharedURLCache].memoryCapacity);

    return resp;
}

- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse forRequest:(NSURLRequest *)request
{
    NSString *myString = [request.URL absoluteString];
    DDLogVerbose(@"URL CACHE SET : PRE  : %@ %d %d %d %d", myString,
                 [NSURLCache sharedURLCache].currentDiskUsage ,
                 [NSURLCache sharedURLCache].currentMemoryUsage,
                 [NSURLCache sharedURLCache].diskCapacity,
                 [NSURLCache sharedURLCache].memoryCapacity);
    [super cachedResponseForRequest:request];
    DDLogVerbose(@"URL CACHE SET : POST : %d %d %d %d",
                [NSURLCache sharedURLCache].currentDiskUsage ,
                [NSURLCache sharedURLCache].currentMemoryUsage,
                [NSURLCache sharedURLCache].diskCapacity,
                [NSURLCache sharedURLCache].memoryCapacity);
}

@end

I also have button code that executes the following:

- (IBAction)onClearButtonPress:(id) sender{
    DDLogVerbose(@"TestViewController onClearButtonPress : START : PRE : %d %d %d %d", 
    [NSURLCache sharedURLCache].currentDiskUsage , 
    [NSURLCache sharedURLCache].currentMemoryUsage, 
    [NSURLCache sharedURLCache].diskCapacity,  
    [NSURLCache sharedURLCache].memoryCapacity);

    [NSURLCache sharedURLCache].removeAllCachedResponses;

    DDLogVerbose(@"TestViewController onClearButtonPress : START : POST : %d %d %d %d", 
    [NSURLCache sharedURLCache].currentDiskUsage , 
    [NSURLCache sharedURLCache].currentMemoryUsage, 
    [NSURLCache sharedURLCache].diskCapacity,  
    [NSURLCache sharedURLCache].memoryCapacity);

    }

When I click some test buttons on my view to fire URLConnection events I see these methods being called with the correct URLS. However, the cache memory and disk usage stats NEVER change.

Example from log

URL CACHE SET : PRE  : https://<domain.com>/resources/images/bg/bg-blue.png 1970176 0 10000000 512000
URL CACHE SET : POST : https://<domain.com>/resources/images/bg/bg-blue.png 1970176 0 10000000 512000

URL CACHE GET : PRE  : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000
URL CACHE GET : POST : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000

TestViewController onClearButtonPress : START : PRE : 1970176 0 10000000 512000
TestViewController onClearButtonPress : EXIT : POST : 1970176 0 10000000 512000

URL CACHE SET : PRE  : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000
URL CACHE SET : POST : https://<domain.com>/resources/images/bg/bg-footer.png 1970176 0 10000000 512000

This makes me believe:

1 – I am doing something wrong, and not correctly observing the cache behavior

2 – This cache is not really caching

Any thoughts would be much appreciated.

  • 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-15T20:07:14+00:00Added an answer on June 15, 2026 at 8:07 pm

    I figured this out a while ago and wanted to post answer.
    I had made my code the delegate for:
    NSURLConnection - connection:willCacheResponse

    That method allows you to override caching behavior before it happens. I has simply placed logging in it to see my Response were cachable, and forgotten to actually do any caching. Once fixed my memory stats logging indeed showed items enter and exiting the cache.

    URL Loading System Programming Guide

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

Sidebar

Related Questions

Attempting to build a C# NPAPI plugin I have found a tutorial which describes
Attempting to get Spring internationalization working. I have used classpath:messages basename, created .properties files
Attempting/struggling to get registration and sign-up working within an active admin project. I have
I have been attempting to use an android.preference.DialogPreference inflated from XML, but the documentation
I am attempting to add a javascript confirm dialog to either my linkbutton onclick
I'm attempting to figure out why some code that I have won't compile and
I wish to have a confirmation on a delete button, and am attempting to
I am attempting to replace the Canvas-based rendering system that I already have with
I have folders with the naming convention: yearmonthday_jobcode_descriptor ie 20101007_GR1234_Whatsit I'm attempting to write
Attempting to disable BSTR caching: SetOaNoCache(); VC++ compiler build output : 'SetOaNoCache': identifier not

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.