EGOCache.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. //
  2. // EGOCache.h
  3. // enormego
  4. //
  5. // Created by Shaun Harrison.
  6. // Copyright (c) 2009-2017 enormego.
  7. //
  8. // Permission is hereby granted, free of charge, to any person obtaining a copy
  9. // of this software and associated documentation files (the "Software"), to deal
  10. // in the Software without restriction, including without limitation the rights
  11. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. // copies of the Software, and to permit persons to whom the Software is
  13. // furnished to do so, subject to the following conditions:
  14. //
  15. // The above copyright notice and this permission notice shall be included in
  16. // all copies or substantial portions of the Software.
  17. //
  18. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. // THE SOFTWARE.
  25. //
  26. #import <Foundation/Foundation.h>
  27. #if TARGET_OS_IPHONE
  28. #import <UIKit/UIKit.h>
  29. #endif
  30. #if TARGET_OS_OSX
  31. #import <AppKit/AppKit.h>
  32. #endif
  33. //! Project version number for EGOCache.
  34. FOUNDATION_EXPORT double EGOCacheVersionNumber;
  35. //! Project version string for EGOCache.
  36. FOUNDATION_EXPORT const unsigned char EGOCacheVersionString[];
  37. #if !__has_feature(nullability)
  38. # define nullable
  39. # define nonnull
  40. # define __nullable
  41. # define __nonnull
  42. #endif
  43. @interface EGOCache : NSObject
  44. // Global cache for easy use
  45. + (nonnull instancetype)globalCache;
  46. // Opitionally create a different EGOCache instance with it's own cache directory
  47. - (nonnull instancetype)initWithCacheDirectory:(NSString* __nonnull)cacheDirectory;
  48. - (void)clearCache;
  49. - (void)removeCacheForKey:(NSString* __nonnull)key;
  50. - (BOOL)hasCacheForKey:(NSString* __nonnull)key;
  51. - (NSData* __nullable)dataForKey:(NSString* __nonnull)key;
  52. - (void)setData:(NSData* __nonnull)data forKey:(NSString* __nonnull)key;
  53. - (void)setData:(NSData* __nonnull)data forKey:(NSString* __nonnull)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  54. - (NSString* __nullable)stringForKey:(NSString* __nonnull)key;
  55. - (void)setString:(NSString* __nonnull)aString forKey:(NSString* __nonnull)key;
  56. - (void)setString:(NSString* __nonnull)aString forKey:(NSString* __nonnull)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  57. - (NSDate* __nullable)dateForKey:(NSString* __nonnull)key;
  58. - (NSArray* __nonnull)allKeys;
  59. #if TARGET_OS_IPHONE
  60. - (UIImage* __nullable)imageForKey:(NSString* __nonnull)key;
  61. - (void)setImage:(UIImage* __nonnull)anImage forKey:(NSString* __nonnull)key;
  62. - (void)setImage:(UIImage* __nonnull)anImage forKey:(NSString* __nonnull)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  63. #else
  64. - (NSImage* __nullable)imageForKey:(NSString* __nonnull)key;
  65. - (void)setImage:(NSImage* __nonnull)anImage forKey:(NSString* __nonnull)key;
  66. - (void)setImage:(NSImage* __nonnull)anImage forKey:(NSString* __nonnull)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  67. #endif
  68. - (NSData* __nullable)plistForKey:(NSString* __nonnull)key;
  69. - (void)setPlist:(nonnull id)plistObject forKey:(NSString* __nonnull)key;
  70. - (void)setPlist:(nonnull id)plistObject forKey:(NSString* __nonnull)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  71. - (void)copyFilePath:(NSString* __nonnull)filePath asKey:(NSString* __nonnull)key;
  72. - (void)copyFilePath:(NSString* __nonnull)filePath asKey:(NSString* __nonnull)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  73. - (nullable id<NSCoding>)objectForKey:(NSString* __nonnull)key;
  74. - (void)setObject:(nonnull id<NSCoding>)anObject forKey:(NSString* __nonnull)key;
  75. - (void)setObject:(nonnull id<NSCoding>)anObject forKey:(NSString* __nonnull)key withTimeoutInterval:(NSTimeInterval)timeoutInterval;
  76. @property(nonatomic) NSTimeInterval defaultTimeoutInterval; // Default is 1 day
  77. @end