Fix compile errors
[pithos-ios] / Classes / ASICacheDelegate.h
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 (ASICachePermanentlyCacheStoragePolicy)
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 ASIDefaultCachePolicy
57 - (ASICachePolicy)defaultCachePolicy;
58
59 - (BOOL)canUseCachedDataForRequest:(ASIHTTPRequest *)request;
60
61 // Should Remove cached data for a particular request
62 - (void)removeCachedDataForRequest:(ASIHTTPRequest *)request;
63
64 // Should return YES if the cache considers its cached response current for the request
65 // Should return NO is the data is not cached, or (for example) if the cached headers state the request should have expired
66 - (BOOL)isCachedDataCurrentForRequest:(ASIHTTPRequest *)request;
67
68 // Should store the response for the passed request in the cache
69 // When a non-zero maxAge is passed, it should be used as the expiry time for the cached response
70 - (void)storeResponseForRequest:(ASIHTTPRequest *)request maxAge:(NSTimeInterval)maxAge;
71
72 // Should return an NSDictionary of cached headers for the passed URL, if it is stored in the cache
73 - (NSDictionary *)cachedResponseHeadersForURL:(NSURL *)url;
74
75 // Should return the cached body of a response for the passed URL, if it is stored in the cache
76 - (NSData *)cachedResponseDataForURL:(NSURL *)url;
77
78 // Returns a path to the cached response data, if it exists
79 - (NSString *)pathToCachedResponseDataForURL:(NSURL *)url;
80
81 // Returns a path to the cached response headers, if they url
82 - (NSString *)pathToCachedResponseHeadersForURL:(NSURL *)request;
83
84 // Returns the location to use to store cached response headers for a particular request
85 - (NSString *)pathToStoreCachedResponseHeadersForRequest:(ASIHTTPRequest *)request;
86
87 // Returns the location to use to store a cached response body for a particular request
88 - (NSString *)pathToStoreCachedResponseDataForRequest:(ASIHTTPRequest *)request;
89
90 // Clear cached data stored for the passed storage policy
91 - (void)clearCachedResponsesForStoragePolicy:(ASICacheStoragePolicy)cachePolicy;
92
93 @end