Statistics
| Branch: | Revision:

root / asi-http-request-with-pithos / Classes / ASICacheDelegate.h @ be116d22

History | View | Annotate | Download (5 kB)

1
//
2
//  ASICacheDelegate.h
3
//  Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest
4
//
5
//  Created by Ben Copsey on 01/05/2010.
6
//  Copyright 2010 All-Seeing Interactive. All rights reserved.
7
//
8

    
9
#import <Foundation/Foundation.h>
10
@class ASIHTTPRequest;
11

    
12
// Cache policies control the behaviour of a cache and how requests use the cache
13
// When setting a cache policy, you can use a combination of these values as a bitmask
14
// For example: [request setCachePolicy:ASIAskServerIfModifiedCachePolicy|ASIFallbackToCacheIfLoadFailsCachePolicy|ASIDoNotWriteToCacheCachePolicy];
15
// Note that some of the behaviours below are mutally exclusive - you cannot combine ASIAskServerIfModifiedWhenStaleCachePolicy and ASIAskServerIfModifiedCachePolicy, for example.
16
typedef enum _ASICachePolicy {
17

    
18
        // The default cache policy. When you set a request to use this, it will use the cache's defaultCachePolicy
19
        // ASIDownloadCache's default cache policy is 'ASIAskServerIfModifiedWhenStaleCachePolicy'
20
        ASIUseDefaultCachePolicy = 0,
21

    
22
        // Tell the request not to read from the cache
23
        ASIDoNotReadFromCacheCachePolicy = 1,
24

    
25
        // The the request not to write to the cache
26
        ASIDoNotWriteToCacheCachePolicy = 2,
27

    
28
        // Ask the server if there is an updated version of this resource (using a conditional GET) ONLY when the cached data is stale
29
        ASIAskServerIfModifiedWhenStaleCachePolicy = 4,
30

    
31
        // Always ask the server if there is an updated version of this resource (using a conditional GET)
32
        ASIAskServerIfModifiedCachePolicy = 8,
33

    
34
        // If cached data exists, use it even if it is stale. This means requests will not talk to the server unless the resource they are requesting is not in the cache
35
        ASIOnlyLoadIfNotCachedCachePolicy = 16,
36

    
37
        // If cached data exists, use it even if it is stale. If cached data does not exist, stop (will not set an error on the request)
38
        ASIDontLoadCachePolicy = 32,
39

    
40
        // Specifies that cached data may be used if the request fails. If cached data is used, the request will succeed without error. Usually used in combination with other options above.
41
        ASIFallbackToCacheIfLoadFailsCachePolicy = 64
42
} ASICachePolicy;
43

    
44
// Cache storage policies control whether cached data persists between application launches (ASICachePermanentlyCacheStoragePolicy) or not (ASICacheForSessionDurationCacheStoragePolicy)
45
// Calling [ASIHTTPRequest clearSession] will remove any data stored using ASICacheForSessionDurationCacheStoragePolicy
46
typedef enum _ASICacheStoragePolicy {
47
        ASICacheForSessionDurationCacheStoragePolicy = 0,
48
        ASICachePermanentlyCacheStoragePolicy = 1
49
} ASICacheStoragePolicy;
50

    
51

    
52
@protocol ASICacheDelegate <NSObject>
53

    
54
@required
55

    
56
// Should return the cache policy that will be used when requests have their cache policy set to ASIUseDefaultCachePolicy
57
- (ASICachePolicy)defaultCachePolicy;
58

    
59
// Returns the date a cached response should expire on. Pass a non-zero max age to specify a custom date.
60
- (NSDate *)expiryDateForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;
61

    
62
// Updates cached response headers with a new expiry date. Pass a non-zero max age to specify a custom date.
63
- (void)updateExpiryForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;
64

    
65
// Looks at the request's cache policy and any cached headers to determine if the cache data is still valid
66
- (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request;
67

    
68
// Removes cached data for a particular request
69
- (void)removeCachedDataForRequest:(ASIHTTPRequest *)request;
70

    
71
// Should return YES if the cache considers its cached response current for the request
72
// Should return NO is the data is not cached, or (for example) if the cached headers state the request should have expired
73
- (BOOL)isCachedDataCurrentForRequest:(ASIHTTPRequest *)request;
74

    
75
// Should store the response for the passed request in the cache
76
// When a non-zero maxAge is passed, it should be used as the expiry time for the cached response
77
- (void)storeResponseForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;
78

    
79
// Removes cached data for a particular url
80
- (void)removeCachedDataForURL:(NSURL *)url;
81

    
82
// Should return an NSDictionary of cached headers for the passed URL, if it is stored in the cache
83
- (NSDictionary *)cachedResponseHeadersForURL:(NSURL *)url;
84

    
85
// Should return the cached body of a response for the passed URL, if it is stored in the cache
86
- (NSData *)cachedResponseDataForURL:(NSURL *)url;
87

    
88
// Returns a path to the cached response data, if it exists
89
- (NSString *)pathToCachedResponseDataForURL:(NSURL *)url;
90

    
91
// Returns a path to the cached response headers, if they url
92
- (NSString *)pathToCachedResponseHeadersForURL:(NSURL *)url;
93

    
94
// Returns the location to use to store cached response headers for a particular request
95
- (NSString *)pathToStoreCachedResponseHeadersForRequest:(ASIHTTPRequest *)request;
96

    
97
// Returns the location to use to store a cached response body for a particular request
98
- (NSString *)pathToStoreCachedResponseDataForRequest:(ASIHTTPRequest *)request;
99

    
100
// Clear cached data stored for the passed storage policy
101
- (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)cachePolicy;
102

    
103
@end