iospdfcache-controlpspdfkit

Can't clear the cache of PSPDFDocument


I'm having problems with clearing the cache of PSPDFDocument before and after deleting the PDF file.

here's what I do:

// ...
PSPDFDocument *document = [PSPDFDocument PDFDocumentWithUrl:(pdfURL)];
[document clearCacheForced:YES];

[mManagedObjectContext deleteObject:mPdfDocument];
// ...

when I try to clear entire cache for all PDFs, it works:

// ...
[[PSPDFCache sharedPSPDFCache] clearCache];
// ...

Any ideas?


Solution

  • Well, the method name is a bit misleading, clearCacheForced on PSPDFDocument just releases some internal cache like the document page count, coordinates, annotation positions - not image content that is cached to disk by PSPDFCache. You need to call

    - (void)removeCacheForDocument:(PSPDFDocument *)aDocument deleteDocument:(BOOL)deleteMagazine
    

    in PSPDFCache to remove the cached images.

    Also see the API documentation: http://pspdfkit.com/documentation/Classes/PSPDFCache.html#//api/name/removeCacheForDocument:deleteDocument: