VICacheManager.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //
  2. // VICacheManager.h
  3. // VIMediaCacheDemo
  4. //
  5. // Created by Vito on 4/21/16.
  6. // Copyright © 2016 Vito. All rights reserved.
  7. //
  8. #import <Foundation/Foundation.h>
  9. #import "VICacheConfiguration.h"
  10. extern NSString *VICacheManagerDidUpdateCacheNotification;
  11. extern NSString *VICacheManagerDidFinishCacheNotification;
  12. extern NSString *VICacheConfigurationKey;
  13. extern NSString *VICacheFinishedErrorKey;
  14. @interface VICacheManager : NSObject
  15. + (void)setCacheDirectory:(NSString *)cacheDirectory;
  16. + (NSString *)cacheDirectory;
  17. /**
  18. How often trigger `VICacheManagerDidUpdateCacheNotification` notification
  19. @param interval Minimum interval
  20. */
  21. + (void)setCacheUpdateNotifyInterval:(NSTimeInterval)interval;
  22. + (NSTimeInterval)cacheUpdateNotifyInterval;
  23. + (NSString *)cachedFilePathForURL:(NSURL *)url;
  24. + (VICacheConfiguration *)cacheConfigurationForURL:(NSURL *)url;
  25. + (void)setFileNameRules:(NSString *(^)(NSURL *url))rules;
  26. /**
  27. Calculate cached files size
  28. @param error If error not empty, calculate failed
  29. @return files size, respresent by `byte`, if error occurs, return -1
  30. */
  31. + (unsigned long long)calculateCachedSizeWithError:(NSError **)error;
  32. + (void)cleanAllCacheWithError:(NSError **)error;
  33. + (void)cleanCacheForURL:(NSURL *)url error:(NSError **)error;
  34. /**
  35. Useful when you upload a local file to the server
  36. @param filePath local file path
  37. @param url remote resource url
  38. @param error On input, a pointer to an error object. If an error occurs, this pointer is set to an actual error object containing the error information.
  39. */
  40. + (BOOL)addCacheFile:(NSString *)filePath forURL:(NSURL *)url error:(NSError **)error;
  41. @end