forked from rs/SDURLCache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDURLCache.h
94 lines (79 loc) · 3.17 KB
/
SDURLCache.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
//
// SDURLCache.h
// SDURLCache
//
// Created by Olivier Poitrey on 15/03/10.
// Copyright 2010 Dailymotion. All rights reserved.
//
#import <Foundation/Foundation.h>
extern NSString *const kSDURLCacheVersion;
@interface SDURLCache : NSURLCache
{
@private
NSString *diskCachePath;
NSMutableDictionary *diskCacheInfo;
BOOL diskCacheInfoDirty, ignoreMemoryOnlyStoragePolicy, disabled, _enableForIOS5AndUp;
NSUInteger diskCacheUsage;
NSTimeInterval minDiskCacheItemInterval;
NSTimeInterval maxMemoryCacheItemInterval;
NSUInteger maxMemoryCacheItemSize;
NSOperationQueue *ioQueue;
NSTimer *periodicMaintenanceTimer;
NSOperation *periodicMaintenanceOperation;
}
/*
* Defines the minimum number of seconds between now and the expiration time of a cacheable response
* in order for the response to be cached on disk. This prevent from spending time and storage capacity
* for an entry which will certainly expire before behing read back from disk cache (memory cache is
* best suited for short term cache). The default value is set to 5 minutes (300 seconds).
*/
@property (nonatomic, assign) NSTimeInterval minDiskCacheItemInterval;
/*
* Defines the maximum number of seconds between now and the expiration time of a cacheable response
* in order for the response to be cached in memory. Responses that have a very long time to live will
* only be cached on disk.
*/
@property (nonatomic, assign) NSTimeInterval maxMemoryCacheItemInterval;
/* Defines the maximum size of a cacheable response in order for the response to be cached in memory.
*/
@property (nonatomic, assign) NSUInteger maxMemoryCacheItemSize;
/*
* Allow the responses that have a storage policy of NSURLCacheStorageAllowedInMemoryOnly to be cached
* on the disk anyway.
*
* This is mainly a workaround against cache policies generated by the UIWebViews: starting from iOS 4.2,
* it always has a cache policy of NSURLCacheStorageAllowedInMemoryOnly.
* The default value is YES
*/
@property (nonatomic, assign) BOOL ignoreMemoryOnlyStoragePolicy;
/*
* Returns a default cache director path to be used at cache initialization. The generated path directory
* will be located in the application's cache directory and thus won't be synced by iTunes.
*/
+ (NSString *)defaultCachePath;
/*
* yosit: It turns that although ios > 5 has a disk cache it doesn't behave in a predicatable way
* the added enableForIOS5AndUp will enable SDURLCache to function like it does on all version of IOS
*/
- (id)initWithMemoryCapacity:(NSUInteger)memoryCapacity
diskCapacity:(NSUInteger)diskCapacity
diskPath:(NSString *)path
enableForIOS5AndUp:(BOOL)enableForIOS5AndUp;
/*
* Checks if the provided URL exists in cache.
*/
- (BOOL)isCached:(NSURL *)url;
/* Clears the memory cache (but not the disk cache)
*/
- (void)clearMemoryCache;
/**
* If you need to reverse the hash on a cacheKey, this is how to do it.
*/
- (NSString *)urlStringForCacheKey:(NSString *)key;
/**
* overwriteExisting defaults to NO
*/
- (void)storeCachedResponse:(NSCachedURLResponse *)cachedResponse
forRequest:(NSURLRequest *)request
overwriteOnDisk:(BOOL)overwrite;
@end