14
|
1 /**
|
|
2 * Copyright: Copyright (c) 2009 Jacob Carlborg.
|
|
3 * Authors: Jacob Carlborg
|
|
4 * Version: Initial created: Aug 3, 2009
|
|
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0)
|
|
6 */
|
|
7 module dstep.foundation.NSURLCache;
|
|
8
|
|
9 import dstep.AvailabilityMacros;
|
|
10 import dstep.foundation.NSCachedURLResponseInternal;
|
|
11 import dstep.foundation.NSData;
|
|
12 import dstep.foundation.NSDictionary;
|
|
13 import dstep.foundation.NSObject;
|
|
14 import dstep.foundation.NSURLCacheInternal;
|
|
15 import dstep.foundation.NSURLRequest;
|
|
16 import dstep.foundation.NSURLResponse;
|
|
17 import dstep.objc.bridge.Bridge;
|
|
18 import dstep.objc.objc : id;
|
|
19
|
|
20 alias NSUInteger NSURLCacheStoragePolicy;
|
|
21
|
|
22 enum
|
|
23 {
|
|
24 NSURLCacheStorageAllowed,
|
|
25 NSURLCacheStorageAllowedInMemoryOnly,
|
|
26 NSURLCacheStorageNotAllowed
|
|
27 }
|
|
28
|
|
29 class NSCachedURLResponse : NSObject, INSCoding, INSCopying
|
|
30 {
|
|
31 mixin ObjcWrap;
|
|
32
|
|
33 Object initWithResponse (NSURLResponse response, NSData data)
|
|
34 {
|
|
35 return invokeObjcSelf!(Object, "initWithResponse:data:", NSURLResponse, NSData)(response, data);
|
|
36 }
|
|
37
|
|
38 this (NSURLResponse response, NSData data)
|
|
39 {
|
|
40 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
41 id result = Bridge.invokeObjcMethod!(id, "initWithResponse:data:", NSURLResponse, NSData)(objcObject, response, data);
|
|
42
|
|
43 if (result)
|
|
44 objcObject = ret;
|
|
45
|
|
46 dObject = this;
|
|
47 }
|
|
48
|
|
49 Object initWithResponse (NSURLResponse response, NSData data, NSDictionary userInfo, uint storagePolicy)
|
|
50 {
|
|
51 return invokeObjcSelf!(Object, "initWithResponse:data:userInfo:storagePolicy:", NSURLResponse, NSData, NSDictionary, uint)(response, data, userInfo, storagePolicy);
|
|
52 }
|
|
53
|
|
54 this (NSURLResponse response, NSData data, NSDictionary userInfo, uint storagePolicy)
|
|
55 {
|
|
56 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
57 id result = Bridge.invokeObjcMethod!(id, "initWithResponse:data:userInfo:storagePolicy:", NSURLResponse, NSData, NSDictionary, uint)(objcObject, response, data, userInfo, storagePolicy);
|
|
58
|
|
59 if (result)
|
|
60 objcObject = ret;
|
|
61
|
|
62 dObject = this;
|
|
63 }
|
|
64
|
|
65 NSURLResponse response ()
|
|
66 {
|
|
67 return invokeObjcSelf!(NSURLResponse, "response");
|
|
68 }
|
|
69
|
|
70 NSData data ()
|
|
71 {
|
|
72 return invokeObjcSelf!(NSData, "data");
|
|
73 }
|
|
74
|
|
75 NSDictionary userInfo ()
|
|
76 {
|
|
77 return invokeObjcSelf!(NSDictionary, "userInfo");
|
|
78 }
|
|
79
|
|
80 uint storagePolicy ()
|
|
81 {
|
|
82 return invokeObjcSelf!(uint, "storagePolicy");
|
|
83 }
|
|
84
|
|
85 void encodeWithCoder (NSCoder aCoder)
|
|
86 {
|
|
87 return invokeObjcSelf!(void, "encodeWithCoder:", NSCoder)(aCoder);
|
|
88 }
|
|
89
|
|
90 Object initWithCoder (NSCoder aDecoder)
|
|
91 {
|
|
92 return invokeObjcSelf!(Object, "initWithCoder:", NSCoder)(aDecoder);
|
|
93 }
|
|
94
|
|
95 this (NSCoder aDecoder)
|
|
96 {
|
|
97 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
98 id result = Bridge.invokeObjcMethod!(id, "initWithCoder:", NSCoder)(objcObject, aDecoder);
|
|
99
|
|
100 if (result)
|
|
101 objcObject = ret;
|
|
102
|
|
103 dObject = this;
|
|
104 }
|
|
105
|
|
106 Object copyWithZone (NSZone* zone)
|
|
107 {
|
|
108 return invokeObjcSelf!(Object, "copyWithZone:", NSZone*)(zone);
|
|
109 }
|
|
110 }
|
|
111
|
|
112 class NSURLCache : NSObject
|
|
113 {
|
|
114 mixin ObjcWrap;
|
|
115
|
|
116 static NSURLCache sharedURLCache ()
|
|
117 {
|
|
118 return invokeObjcSelfClass!(NSURLCache, "sharedURLCache"return result is this.objcObject ? this : (result !is null ? new NSURLCache(result) : null); }
|
|
119
|
|
120 static void setSharedURLCache (NSURLCache cache)
|
|
121 {
|
|
122 return invokeObjcSelfClass!(void, "setSharedURLCache:", NSURLCache)(cache);
|
|
123 }
|
|
124
|
|
125 Object initWithMemoryCapacity (NSUInteger memoryCapacity, NSUInteger diskCapacity, NSString path)
|
|
126 {
|
|
127 return invokeObjcSelf!(Object, "initWithMemoryCapacity:diskCapacity:diskPath:", NSUInteger, NSUInteger, NSString)(memoryCapacity, diskCapacity, path);
|
|
128 }
|
|
129
|
|
130 this (NSUInteger memoryCapacity, NSUInteger diskCapacity, NSString path)
|
|
131 {
|
|
132 objcObject = Bridge.invokeObjcClassMethod!(id, "alloc")(objcClass);
|
|
133 id result = Bridge.invokeObjcMethod!(id, "initWithMemoryCapacity:diskCapacity:diskPath:", NSUInteger, NSUInteger, NSString)(objcObject, memoryCapacity, diskCapacity, path);
|
|
134
|
|
135 if (result)
|
|
136 objcObject = ret;
|
|
137
|
|
138 dObject = this;
|
|
139 }
|
|
140
|
|
141 NSCachedURLResponse cachedResponseForRequest (NSURLRequest request)
|
|
142 {
|
|
143 return invokeObjcSelf!(NSCachedURLResponse, "cachedResponseForRequest:", NSURLRequest)(request);
|
|
144 }
|
|
145
|
|
146 void storeCachedResponse (NSCachedURLResponse cachedResponse, NSURLRequest request)
|
|
147 {
|
|
148 return invokeObjcSelf!(void, "storeCachedResponse:forRequest:", NSCachedURLResponse, NSURLRequest)(cachedResponse, request);
|
|
149 }
|
|
150
|
|
151 void removeCachedResponseForRequest (NSURLRequest request)
|
|
152 {
|
|
153 return invokeObjcSelf!(void, "removeCachedResponseForRequest:", NSURLRequest)(request);
|
|
154 }
|
|
155
|
|
156 void removeAllCachedResponses ()
|
|
157 {
|
|
158 return invokeObjcSelf!(void, "removeAllCachedResponses");
|
|
159 }
|
|
160
|
|
161 NSUInteger memoryCapacity ()
|
|
162 {
|
|
163 return invokeObjcSelf!(NSUInteger, "memoryCapacity");
|
|
164 }
|
|
165
|
|
166 NSUInteger diskCapacity ()
|
|
167 {
|
|
168 return invokeObjcSelf!(NSUInteger, "diskCapacity");
|
|
169 }
|
|
170
|
|
171 void setMemoryCapacity (NSUInteger memoryCapacity)
|
|
172 {
|
|
173 return invokeObjcSelf!(void, "setMemoryCapacity:", NSUInteger)(memoryCapacity);
|
|
174 }
|
|
175
|
|
176 void setDiskCapacity (NSUInteger diskCapacity)
|
|
177 {
|
|
178 return invokeObjcSelf!(void, "setDiskCapacity:", NSUInteger)(diskCapacity);
|
|
179 }
|
|
180
|
|
181 NSUInteger currentMemoryUsage ()
|
|
182 {
|
|
183 return invokeObjcSelf!(NSUInteger, "currentMemoryUsage");
|
|
184 }
|
|
185
|
|
186 NSUInteger currentDiskUsage ()
|
|
187 {
|
|
188 return invokeObjcSelf!(NSUInteger, "currentDiskUsage");
|
|
189 }
|
|
190 }
|
|
191
|