PSPDFCache
Objective-C
@interface PSPDFCache : NSObject
Swift
class PDFCache : NSObject
The PDFCache
is responsible for managing the memory and disk cache of rendered
images.
Usually you do not access any methods of PDFCache
directly but instead schedule
a RenderTask
in a RenderQueue
which will then reach out to the cache
and check if there are images available before rendering a new one.
The cache can be accessed with PSPDFKit.SDK.shared.cache
.
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 memory cached store used to keep images in memory for fast access.
Declaration
Objective-C
@property (nonatomic, readonly) PSPDFMemoryCache *_Nonnull memoryCache;
Swift
var memoryCache: PSPDFMemoryCache { get }
-
The disk cache used to persist images on disk for fast access.
Declaration
Objective-C
@property (nonatomic, readonly) PSPDFDiskCache *_Nonnull diskCache;
Swift
var diskCache: PSPDFDiskCache { get }
-
Get the cache status of a rendered image.
Declaration
Objective-C
- (PSPDFCacheStatus)cacheStatusForRequest:(nonnull PSPDFRenderRequest *)request imageSizeMatching: (PSPDFCacheImageSizeMatching)imageSizeMatching;
Swift
func cacheStatus(for request: PSPDFRenderRequest, imageSizeMatching: PDFCache.ImageSizeMatching) -> PDFCache.Status
-
Get the image for a certain document page. Will first check the memory cache, then the disk cache.
If
requireExactSize
is set, images will either be downscaled or dynamically rendered. (There’s no point in upscaling)Declaration
Objective-C
- (nullable UIImage *)imageForRequest:(nonnull PSPDFRenderRequest *)request imageSizeMatching: (PSPDFCacheImageSizeMatching)imageSizeMatching error:(NSError *_Nullable *_Nullable)error;
Swift
func image(for request: PSPDFRenderRequest, imageSizeMatching: PDFCache.ImageSizeMatching) throws -> UIImage
-
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 UIImage *)image forRequest:(nonnull PSPDFRenderRequest *)request;
Swift
func save(_ image: UIImage, 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?)
-
Removes images from the disk and memory cache for a single page in a document.
This usually is called after an annotation changes (and thus the page 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)
-
Removes images from the disk and memory cache for a single page in a document.
This usually is called after an annotation changes (and thus the page needs to be re-rendered).
Declaration
Objective-C
- (void)removeImagesForDocumentWithUID:(nonnull NSString *)documentUID pageIndex:(PSPDFPageIndex)pageIndex;
Swift
func removeImages(forDocumentWithUID documentUID: String, pageIndex: PageIndex)
-
Removes images from the disk and memory cache for several pages in a document. This usually is called after an annotation changes (and thus the page 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 images from the disk and memory cache for several pages in a document.
This usually is called after an annotation changes (and thus the page needs to be re-rendered).
Declaration
Objective-C
- (void)removeImagesForDocumentWithUID:(nonnull NSString *)documentUID pageIndexes:(nonnull NSIndexSet *)indexes;
Swift
func removeImages(forDocumentWithUID documentUID: String, pageIndexes indexes: IndexSet)
-
Removes all images from the disk and memory cache for a document. This also cancels any in progress cache requests for the document.
Declaration
Objective-C
- (void)removeCacheForDocument:(nullable PSPDFDocument *)document;
Swift
func remove(for document: PSPDFDocument?)
-
Removes all images from the disk and memory cache for a document.
Declaration
Objective-C
- (void)removeImagesForDocumentWithUID:(nonnull NSString *)documentUID;
Swift
func removeImages(forDocumentWithUID documentUID: String)
-
Removes all images from the disk and memory cache.