PSPDFCache

Objective-C


@interface PSPDFCache : NSObject

Swift

class PDFCache : NSObject

The PSPDFCache is responsible for managing the memory and disk cache of rendered images.

Usually you do not access any methods of PSPDFCache directly but instead schedule a PSPDFRenderTask in a PSPDFRenderQueue which will then reach out to the cache and check if there are images available before rendering a new one.

See

PSPDFRenderTask
  • Unavailable

    Not the designated initializer

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • Unavailable

    Not the designated initializer

    Undocumented

    Declaration

    Objective-C

    PSPDF_EMPTY_INIT_UNAVAILABLE
  • The designated initializer.

    Declaration

    Objective-C

    - (nonnull instancetype)initWithSettings:(nonnull PSPDFKitGlobal *)pspdfkit;

    Swift

    init(settings pspdfkit: PSPDFKitGlobal)
  • Caches the image in memory and disk for later re-use. PSPDFCache will decide at runtime if the image is worth saving into memory or just disk. (And disk will only be hit if the image is different)

    Declaration

    Objective-C

    - (void)saveImage:(nonnull NSImage *)image
           forRequest:(nonnull PSPDFRenderRequest *)request;

    Swift

    func save(_ image: NSImage, for request: PSPDFRenderRequest)
  • Asynchronously pre-renders and caches the document. The delegate method didRenderImage:document:page:size: gets called after each image is rendered (number of pages x number of sizes).

    Note

    Under certain conditions (such as if the device is running low on power) the cache may suspend pre caching operations until everything has been restored to normal conditions.

    Declaration

    Objective-C

    - (void)cacheDocument:(nullable PSPDFDocument *)document
            withPageSizes:(nonnull NSArray<NSValue *> *)sizes;

    Swift

    func cacheDocument(_ document: PSPDFDocument?, withPageSizes sizes: [NSValue])

    Parameters

    document

    The document to render and cache — if nil, this message is ignored.

    sizes

    An array of NSValue objects constructed with CGSize. Each page will be rendered for each size specified in this array.

  • Asynchronously pre-renders and caches the document. The delegate method didRenderImage:document:page:size: gets called after each image is rendered (number of pages x number of sizes).

    Note

    Under certain conditions (such as if the device is running low on power) the cache may suspend pre caching operations until everything has been restored to normal conditions.

    Declaration

    Objective-C

    - (void)cacheDocument:(nullable PSPDFDocument *)document
                        withPageSizes:(nonnull NSArray<NSValue *> *)sizes
        imageRenderingCompletionBlock:
            (nullable PSPDFCacheDocumentImageRenderingCompletionBlock)
                pageCompletionBlock;

    Swift

    func cacheDocument(_ document: PSPDFDocument?, withPageSizes sizes: [NSValue], imageRenderingCompletionBlock pageCompletionBlock: PSPDFCacheDocumentImageRenderingCompletionBlock? = nil)

    Parameters

    document

    The document to render and cache — if nil, this message is ignored.

    sizes

    An array of NSValue objects constructed with CGSize. Each page will be rendered for each size specified in this array.

    pageCompletionBlock

    This block will be executed each time a page is rendered for each size (the delegates, if any, will still be called!).

  • Stops all cache requests (render requests, queued disk writes) for the document.

    Declaration

    Objective-C

    - (void)stopCachingDocument:(nullable PSPDFDocument *)document;

    Swift

    func stopCachingDocument(_ document: PSPDFDocument?)
  • Invalidates a single page in the document. This usually is called after an annotation changes (and thus the image needs to be re-rendered)

    Note

    If the document is nil, the request is silently ignored.

    Declaration

    Objective-C

    - (void)invalidateImagesFromDocument:(nullable PSPDFDocument *)document
                               pageIndex:(PSPDFPageIndex)pageIndex;

    Swift

    func invalidateImages(from document: PSPDFDocument?, pageIndex: PageIndex)
  • Invalidates pages in the document. This usually is called after an annotation changes (and thus the image needs to be re-rendered)

    Note

    If the document is nil, the request is silently ignored.

    Declaration

    Objective-C

    - (void)invalidateImagesFromDocument:(nullable PSPDFDocument *const)document
                                 indexes:(nonnull NSIndexSet *)indexes;

    Swift

    func invalidateImages(from document: PSPDFDocument?, indexes: IndexSet)
  • Removes the whole cache (memory/disk) for document. Will cancel any open writes as well. Enable deleteDocument to remove the document and the associated metadata.

    Declaration

    Objective-C

    - (void)removeCacheForDocument:(nullable PSPDFDocument *)document;

    Swift

    func remove(for document: PSPDFDocument?)
  • Clears the disk and memory cache.

    Declaration

    Objective-C

    - (void)clearCache;

    Swift

    func clear()