PSPDFCache Class Reference
| Inherits from | NSObject |
| Conforms to | PSPDFRenderDelegate |
| Declared in | PSPDFCache.h |
Overview
This singleton manages both memory and disk cache, and adds new render requests to PSPDFRenderQueue. Most settings are device dependant.
Tasks
Other Methods
-
+ sharedCacheThe cache object is a singleton.
Access cache
-
– cacheStatusForImageFromDocument:andPage:withSize:options:Get the cache status of a rendered image.
optionswill ignore all entires except PSPDFCacheOptionSize*. -
– imageFromDocument:andPage:withSize:options:Get the image for a certain document page. Will first check the memory cache, then the disk cache and lastly queues a request to render. Returns the image instantly if the memory cache was filled, else will queue and call the delegate. If
requireExactSizeis set, images will either be downscaled or dynamically rendered. (There’s no point in upscaling)
Store into cache
-
– saveImage:fromDocument:andPage:withReceipt: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)
Document preprocessing
-
– cacheDocument:startAtPage:sizes:diskCacheStrategy:Starts caching the document. setting
diskCacheStrategyto PSPDFDiskCacheStrategyEverything will pre-cache the whole document, and PSPDFDiskCacheStrategyNearPages will render a few pages aroundpage. -
– stopCachingDocument:Stops all cache requests (render requests, queued disk writes) for the document.
Cache invalidation
-
– cancelRequestForImageFromDocument:andPage:withSize:Cancels any open image request (disk load/render).
-
– invalidateImageFromDocument:andPage:Allows to invalidate a single page in the document. This usually is called after an annotation changes (and thus the image needs to be re-rendered)
-
– removeCacheForDocument:deleteDocument:error:Removes the whole cache (memory/disk) for
document. Will cancel any open writes as well. EnabledeleteDocumentto remove the document and the associated metadata. -
– clearCacheClears the disk and memory cache.
Access internal caches
-
memoryCacheAccess the memory cache. Allows deeper customization of the amount of memory used.
property -
diskCacheAccess the disk cache. Allows deeper customization of the amount of disk space used.
property
Settings
-
cacheDirectoryCache files are saved in a subdirectory of NSCachesDirectory. Defaults to “PSPDFKit/Pages”.
property -
diskCacheStrategyDefines the global disk cache strategy. Defaults to PSPDFDiskCacheStrategyEverything. If PSPDFDocument also defines a strategy, that one is priorized.
property -
thumbnailSizeThe size of the thumbnail images used in the grid view and those shown before the full-size versions are rendered. Defaults to (170, 220) on iPad and (85, 110) on iPhone.
property -
tinySizeThe size of the images used in the scrobble bar. Defaults to CGSizeMake(50, 65).
property
Starting/Stopping
-
– pauseCachingForService:Will pause queued cache requests on the render queue. For
serviceuse the class object that requests the pause. -
– resumeCachingForService:Will resume queued cache requests on the render queue. For
serviceuse the class object that requested the pause.
Delegate
-
– addDelegate:Register a delegate to be notifiec of new cache load events.
-
– removeDelegate:Deregisters a delegate.
Disk Cache Settings
-
useJPGFormatJPG is almost always faster, and uses less memory (<50% of a PNG, usually). Defaults to YES. If you have very text-like pages, you might want to set this to NO.
property -
JPGFormatCompressionCompression strength for JPG. (PNG is lossless) The higher the compression, the larger the files and the slower is decompression. Defaults to 0.9. This will load the pdf and remove any jpg artifacts.
property -
allowImageResizeWill allow image resizing instead of re-rendering to generate thumbnails. This is conditionally enabled for older devices. This is a tradeoff between performance or quality.
property
Encryption/Decryption Handlers
-
decryptFromPathBlockDecrypt data from the path. PSPDFKit Annotate feature. If set to nil, the default implementation will be used.
property -
encryptDataBlockEncrypt mutable data. PSPDFKit Annotate feature. If set to nil, the default implementation will be used.
property
Properties
JPGFormatCompression
Compression strength for JPG. (PNG is lossless) The higher the compression, the larger the files and the slower is decompression. Defaults to 0.9. This will load the pdf and remove any jpg artifacts.
@property (nonatomic, assign) CGFloat JPGFormatCompressionDeclared In
PSPDFCache.hallowImageResize
Will allow image resizing instead of re-rendering to generate thumbnails. This is conditionally enabled for older devices. This is a tradeoff between performance or quality.
@property (nonatomic, assign) BOOL allowImageResizeDiscussion
Note: You will need to clear the cache after changing this to see a difference.
Declared In
PSPDFCache.hcacheDirectory
Cache files are saved in a subdirectory of NSCachesDirectory. Defaults to “PSPDFKit/Pages”.
@property (nonatomic, copy) NSString *cacheDirectoryDiscussion
Note: The cache directory is not backed up by iCloud and will be purged when memory is low.
Warning: Set this early during class initialization. Will clear the current chache before changing.
Declared In
PSPDFCache.hdecryptFromPathBlock
Decrypt data from the path. PSPDFKit Annotate feature. If set to nil, the default implementation will be used.
@property (atomic, copy) NSData *^ ) ( PSPDFDocument *document , NSString *path ) decryptFromPathBlockDeclared In
PSPDFCache.hdiskCache
Access the disk cache. Allows deeper customization of the amount of disk space used.
@property (nonatomic, strong, readonly) PSPDFDiskCache *diskCacheDeclared In
PSPDFCache.hdiskCacheStrategy
Defines the global disk cache strategy. Defaults to PSPDFDiskCacheStrategyEverything. If PSPDFDocument also defines a strategy, that one is priorized.
@property (nonatomic, assign) PSPDFDiskCacheStrategy diskCacheStrategyDeclared In
PSPDFCache.hencryptDataBlock
Encrypt mutable data. PSPDFKit Annotate feature. If set to nil, the default implementation will be used.
@property (atomic, copy) void ( ^ ) ( PSPDFDocument *document , NSMutableData *data ) encryptDataBlockDeclared In
PSPDFCache.hmemoryCache
Access the memory cache. Allows deeper customization of the amount of memory used.
@property (nonatomic, strong, readonly) PSPDFMemoryCache *memoryCacheDeclared In
PSPDFCache.hthumbnailSize
The size of the thumbnail images used in the grid view and those shown before the full-size versions are rendered. Defaults to (170, 220) on iPad and (85, 110) on iPhone.
@property (nonatomic, assign) CGSize thumbnailSizeDeclared In
PSPDFCache.hInstance Methods
addDelegate:
Register a delegate to be notifiec of new cache load events.
- (void)addDelegate:(id<PSPDFCacheDelegate>)aDelegateDeclared In
PSPDFCache.hcacheDocument:startAtPage:sizes:diskCacheStrategy:
Starts caching the document. setting diskCacheStrategy to PSPDFDiskCacheStrategyEverything will pre-cache the whole document, and PSPDFDiskCacheStrategyNearPages will render a few pages around page.
- (void)cacheDocument:(PSPDFDocument *)document startAtPage:(NSUInteger)page sizes:(NSArray *)sizes diskCacheStrategy:(PSPDFDiskCacheStrategy)diskCacheStrategyDeclared In
PSPDFCache.hcacheStatusForImageFromDocument:andPage:withSize:options:
Get the cache status of a rendered image.
options will ignore all entires except PSPDFCacheOptionSize*.
- (PSPDFCacheStatus)cacheStatusForImageFromDocument:(PSPDFDocument *)document andPage:(NSUInteger)page withSize:(CGSize)size options:(PSPDFCacheOptions)optionsDeclared In
PSPDFCache.hcancelRequestForImageFromDocument:andPage:withSize:
Cancels any open image request (disk load/render).
- (void)cancelRequestForImageFromDocument:(PSPDFDocument *)document andPage:(NSUInteger)page withSize:(CGSize)sizeDeclared In
PSPDFCache.himageFromDocument:andPage:withSize:options:
Get the image for a certain document page.
Will first check the memory cache, then the disk cache and lastly queues a request to render.
Returns the image instantly if the memory cache was filled, else will queue and call the delegate.
If requireExactSize is set, images will either be downscaled or dynamically rendered. (There’s no point in upscaling)
- (UIImage *)imageFromDocument:(PSPDFDocument *)document andPage:(NSUInteger)page withSize:(CGSize)size options:(PSPDFCacheOptions)optionsDiscussion
Note: The cache will always return an aspect ratio corrected size of the image, so resulting size might be different.
Declared In
PSPDFCache.hinvalidateImageFromDocument:andPage:
Allows to invalidate a single page in the document. This usually is called after an annotation changes (and thus the image needs to be re-rendered)
- (void)invalidateImageFromDocument:(PSPDFDocument *)document andPage:(NSUInteger)pageDeclared In
PSPDFCache.hpauseCachingForService:
Will pause queued cache requests on the render queue.
For service use the class object that requests the pause.
- (BOOL)pauseCachingForService:(id)serviceReturn Value
Returns YES if the cache has been paused.
Declared In
PSPDFCache.hremoveCacheForDocument:deleteDocument:error:
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.
- (BOOL)removeCacheForDocument:(PSPDFDocument *)document deleteDocument:(BOOL)deleteDocument error:(NSError **)errorDeclared In
PSPDFCache.hremoveDelegate:
Deregisters a delegate.
- (BOOL)removeDelegate:(id<PSPDFCacheDelegate>)aDelegateReturn Value
Returns YES on success.
Declared In
PSPDFCache.hresumeCachingForService:
Will resume queued cache requests on the render queue.
For service use the class object that requested the pause.
- (BOOL)resumeCachingForService:(id)serviceReturn Value
Returns YES if the cache has been resumed.
Declared In
PSPDFCache.hsaveImage:fromDocument:andPage:withReceipt:
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)
- (void)saveImage:(UIImage *)image fromDocument:(PSPDFDocument *)document andPage:(NSUInteger)page withReceipt:(NSString *)renderReceiptDeclared In
PSPDFCache.h