objc2_foundation/generated/NSURLCache.rs
1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6
7use crate::*;
8
9/// The NSURLCacheStoragePolicy enum defines constants that
10/// can be used to specify the type of storage that is allowable for an
11/// NSCachedURLResponse object that is to be stored in an NSURLCache.
12///
13///
14/// NSURLCache is allowed without restriction.
15///
16///
17/// storage in an NSURLCache is allowed; however storage should be
18/// done in memory only, no disk storage should be done.
19///
20///
21/// NSURLCache is not allowed in any fashion, either in memory or on
22/// disk.
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcachestoragepolicy?language=objc)
25// NS_ENUM
26#[repr(transparent)]
27#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
28pub struct NSURLCacheStoragePolicy(pub NSUInteger);
29impl NSURLCacheStoragePolicy {
30 #[doc(alias = "NSURLCacheStorageAllowed")]
31 pub const Allowed: Self = Self(0);
32 #[doc(alias = "NSURLCacheStorageAllowedInMemoryOnly")]
33 pub const AllowedInMemoryOnly: Self = Self(1);
34 #[doc(alias = "NSURLCacheStorageNotAllowed")]
35 pub const NotAllowed: Self = Self(2);
36}
37
38unsafe impl Encode for NSURLCacheStoragePolicy {
39 const ENCODING: Encoding = NSUInteger::ENCODING;
40}
41
42unsafe impl RefEncode for NSURLCacheStoragePolicy {
43 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
44}
45
46extern_class!(
47 /// NSCachedURLResponse is a class whose objects functions as a wrapper for
48 /// objects that are stored in the framework's caching system.
49 /// It is used to maintain characteristics and attributes of a cached
50 /// object.
51 ///
52 /// See also [Apple's documentation](https://developer.apple.com/documentation/foundation/nscachedurlresponse?language=objc)
53 #[unsafe(super(NSObject))]
54 #[derive(Debug, PartialEq, Eq, Hash)]
55 pub struct NSCachedURLResponse;
56);
57
58unsafe impl Send for NSCachedURLResponse {}
59
60unsafe impl Sync for NSCachedURLResponse {}
61
62#[cfg(feature = "NSObject")]
63extern_conformance!(
64 unsafe impl NSCoding for NSCachedURLResponse {}
65);
66
67#[cfg(feature = "NSObject")]
68extern_conformance!(
69 unsafe impl NSCopying for NSCachedURLResponse {}
70);
71
72#[cfg(feature = "NSObject")]
73unsafe impl CopyingHelper for NSCachedURLResponse {
74 type Result = Self;
75}
76
77extern_conformance!(
78 unsafe impl NSObjectProtocol for NSCachedURLResponse {}
79);
80
81#[cfg(feature = "NSObject")]
82extern_conformance!(
83 unsafe impl NSSecureCoding for NSCachedURLResponse {}
84);
85
86impl NSCachedURLResponse {
87 extern_methods!(
88 #[cfg(all(feature = "NSData", feature = "NSURLResponse"))]
89 /// Initializes an NSCachedURLResponse with the given
90 /// response and data.
91 ///
92 /// A default NSURLCacheStoragePolicy is used for
93 /// NSCachedURLResponse objects initialized with this method:
94 /// NSURLCacheStorageAllowed.
95 ///
96 /// Parameter `response`: a NSURLResponse object.
97 ///
98 /// Parameter `data`: an NSData object representing the URL content
99 /// corresponding to the given response.
100 ///
101 /// Returns: an initialized NSCachedURLResponse.
102 #[unsafe(method(initWithResponse:data:))]
103 #[unsafe(method_family = init)]
104 pub fn initWithResponse_data(
105 this: Allocated<Self>,
106 response: &NSURLResponse,
107 data: &NSData,
108 ) -> Retained<Self>;
109
110 #[cfg(all(
111 feature = "NSData",
112 feature = "NSDictionary",
113 feature = "NSURLResponse"
114 ))]
115 /// Initializes an NSCachedURLResponse with the given
116 /// response, data, user-info dictionary, and storage policy.
117 ///
118 /// Parameter `response`: a NSURLResponse object.
119 ///
120 /// Parameter `data`: an NSData object representing the URL content
121 /// corresponding to the given response.
122 ///
123 /// Parameter `userInfo`: a dictionary user-specified information to be
124 /// stored with the NSCachedURLResponse.
125 ///
126 /// Parameter `storagePolicy`: an NSURLCacheStoragePolicy constant.
127 ///
128 /// Returns: an initialized NSCachedURLResponse.
129 ///
130 /// # Safety
131 ///
132 /// `user_info` generic should be of the correct type.
133 #[unsafe(method(initWithResponse:data:userInfo:storagePolicy:))]
134 #[unsafe(method_family = init)]
135 pub unsafe fn initWithResponse_data_userInfo_storagePolicy(
136 this: Allocated<Self>,
137 response: &NSURLResponse,
138 data: &NSData,
139 user_info: Option<&NSDictionary>,
140 storage_policy: NSURLCacheStoragePolicy,
141 ) -> Retained<Self>;
142
143 #[cfg(feature = "NSURLResponse")]
144 /// Returns the response wrapped by this instance.
145 ///
146 /// Returns: The response wrapped by this instance.
147 #[unsafe(method(response))]
148 #[unsafe(method_family = none)]
149 pub fn response(&self) -> Retained<NSURLResponse>;
150
151 #[cfg(feature = "NSData")]
152 /// Returns the data of the receiver.
153 ///
154 /// Returns: The data of the receiver.
155 #[unsafe(method(data))]
156 #[unsafe(method_family = none)]
157 pub fn data(&self) -> Retained<NSData>;
158
159 #[cfg(feature = "NSDictionary")]
160 /// Returns the userInfo dictionary of the receiver.
161 ///
162 /// Returns: The userInfo dictionary of the receiver.
163 #[unsafe(method(userInfo))]
164 #[unsafe(method_family = none)]
165 pub fn userInfo(&self) -> Option<Retained<NSDictionary>>;
166
167 /// Returns the NSURLCacheStoragePolicy constant of the receiver.
168 ///
169 /// Returns: The NSURLCacheStoragePolicy constant of the receiver.
170 #[unsafe(method(storagePolicy))]
171 #[unsafe(method_family = none)]
172 pub fn storagePolicy(&self) -> NSURLCacheStoragePolicy;
173 );
174}
175
176/// Methods declared on superclass `NSObject`.
177impl NSCachedURLResponse {
178 extern_methods!(
179 #[unsafe(method(init))]
180 #[unsafe(method_family = init)]
181 pub fn init(this: Allocated<Self>) -> Retained<Self>;
182
183 #[unsafe(method(new))]
184 #[unsafe(method_family = new)]
185 pub fn new() -> Retained<Self>;
186 );
187}
188
189impl DefaultRetained for NSCachedURLResponse {
190 #[inline]
191 fn default_retained() -> Retained<Self> {
192 Self::new()
193 }
194}
195
196extern_class!(
197 /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcache?language=objc)
198 #[unsafe(super(NSObject))]
199 #[derive(Debug, PartialEq, Eq, Hash)]
200 pub struct NSURLCache;
201);
202
203unsafe impl Send for NSURLCache {}
204
205unsafe impl Sync for NSURLCache {}
206
207extern_conformance!(
208 unsafe impl NSObjectProtocol for NSURLCache {}
209);
210
211impl NSURLCache {
212 extern_methods!(
213 /// Returns the shared NSURLCache instance or
214 /// sets the NSURLCache instance shared by all clients of
215 /// the current process. This will be the new object returned when
216 /// calls to the
217 /// <tt>
218 /// sharedURLCache
219 /// </tt>
220 /// method are made.
221 ///
222 /// Unless set explicitly through a call to
223 /// <tt>
224 /// +setSharedURLCache:
225 /// </tt>
226 /// , this method returns an NSURLCache
227 /// instance created with the following default values:
228 /// <ul>
229 /// <li>
230 /// Memory capacity: 4 megabytes (4 * 1024 * 1024 bytes)
231 /// <li>
232 /// Disk capacity: 20 megabytes (20 * 1024 * 1024 bytes)
233 /// <li>
234 /// Disk path:
235 /// <nobr
236 /// >(user home directory)/Library/Caches/(application bundle id)
237 /// </nobr
238 /// >
239 /// </ul>
240 /// <p>
241 /// Users who do not have special caching requirements or
242 /// constraints should find the default shared cache instance
243 /// acceptable. If this default shared cache instance is not
244 /// acceptable,
245 /// <tt>
246 /// +setSharedURLCache:
247 /// </tt>
248 /// can be called to set a
249 /// different NSURLCache instance to be returned from this method.
250 /// Callers should take care to ensure that the setter is called
251 /// at a time when no other caller has a reference to the previously-set
252 /// shared URL cache. This is to prevent storing cache data from
253 /// becoming unexpectedly unretrievable.
254 ///
255 /// Returns: the shared NSURLCache instance.
256 #[unsafe(method(sharedURLCache))]
257 #[unsafe(method_family = none)]
258 pub fn sharedURLCache() -> Retained<NSURLCache>;
259
260 /// Setter for [`sharedURLCache`][Self::sharedURLCache].
261 #[unsafe(method(setSharedURLCache:))]
262 #[unsafe(method_family = none)]
263 pub fn setSharedURLCache(shared_url_cache: &NSURLCache);
264
265 #[cfg(feature = "NSString")]
266 /// Initializes an NSURLCache with the given capacity and
267 /// path.
268 ///
269 /// The returned NSURLCache is backed by disk, so
270 /// developers can be more liberal with space when choosing the
271 /// capacity for this kind of cache. A disk cache measured in the tens
272 /// of megabytes should be acceptable in most cases.
273 ///
274 /// Parameter `memoryCapacity`: the capacity, measured in bytes, for the cache in memory.
275 ///
276 /// Parameter `diskCapacity`: the capacity, measured in bytes, for the cache on disk.
277 ///
278 /// Parameter `path`: the path on disk where the cache data is stored.
279 ///
280 /// Returns: an initialized NSURLCache, with the given capacity, backed
281 /// by disk.
282 #[deprecated]
283 #[unsafe(method(initWithMemoryCapacity:diskCapacity:diskPath:))]
284 #[unsafe(method_family = init)]
285 pub fn initWithMemoryCapacity_diskCapacity_diskPath(
286 this: Allocated<Self>,
287 memory_capacity: NSUInteger,
288 disk_capacity: NSUInteger,
289 path: Option<&NSString>,
290 ) -> Retained<Self>;
291
292 #[cfg(feature = "NSURL")]
293 /// Initializes an NSURLCache with the given capacity and directory.
294 ///
295 /// Parameter `memoryCapacity`: the capacity, measured in bytes, for the cache in memory. Or 0 to disable memory cache.
296 ///
297 /// Parameter `diskCapacity`: the capacity, measured in bytes, for the cache on disk. Or 0 to disable disk cache.
298 ///
299 /// Parameter `directoryURL`: the path to a directory on disk where the cache data is stored. Or nil for default directory.
300 ///
301 /// Returns: an initialized NSURLCache, with the given capacity, optionally backed by disk.
302 #[unsafe(method(initWithMemoryCapacity:diskCapacity:directoryURL:))]
303 #[unsafe(method_family = init)]
304 pub fn initWithMemoryCapacity_diskCapacity_directoryURL(
305 this: Allocated<Self>,
306 memory_capacity: NSUInteger,
307 disk_capacity: NSUInteger,
308 directory_url: Option<&NSURL>,
309 ) -> Retained<Self>;
310
311 #[cfg(feature = "NSURLRequest")]
312 /// Returns the NSCachedURLResponse stored in the cache with
313 /// the given request.
314 ///
315 /// The method returns nil if there is no
316 /// NSCachedURLResponse stored using the given request.
317 ///
318 /// Parameter `request`: the NSURLRequest to use as a key for the lookup.
319 ///
320 /// Returns: The NSCachedURLResponse stored in the cache with the given
321 /// request, or nil if there is no NSCachedURLResponse stored with the
322 /// given request.
323 #[unsafe(method(cachedResponseForRequest:))]
324 #[unsafe(method_family = none)]
325 pub fn cachedResponseForRequest(
326 &self,
327 request: &NSURLRequest,
328 ) -> Option<Retained<NSCachedURLResponse>>;
329
330 #[cfg(feature = "NSURLRequest")]
331 /// Stores the given NSCachedURLResponse in the cache using
332 /// the given request.
333 ///
334 /// Parameter `cachedResponse`: The cached response to store.
335 ///
336 /// Parameter `request`: the NSURLRequest to use as a key for the storage.
337 #[unsafe(method(storeCachedResponse:forRequest:))]
338 #[unsafe(method_family = none)]
339 pub fn storeCachedResponse_forRequest(
340 &self,
341 cached_response: &NSCachedURLResponse,
342 request: &NSURLRequest,
343 );
344
345 #[cfg(feature = "NSURLRequest")]
346 /// Removes the NSCachedURLResponse from the cache that is
347 /// stored using the given request.
348 ///
349 /// No action is taken if there is no NSCachedURLResponse
350 /// stored with the given request.
351 ///
352 /// Parameter `request`: the NSURLRequest to use as a key for the lookup.
353 #[unsafe(method(removeCachedResponseForRequest:))]
354 #[unsafe(method_family = none)]
355 pub fn removeCachedResponseForRequest(&self, request: &NSURLRequest);
356
357 /// Clears the given cache, removing all NSCachedURLResponse
358 /// objects that it stores.
359 #[unsafe(method(removeAllCachedResponses))]
360 #[unsafe(method_family = none)]
361 pub fn removeAllCachedResponses(&self);
362
363 #[cfg(feature = "NSDate")]
364 /// Clears the given cache of any cached responses since the provided date.
365 #[unsafe(method(removeCachedResponsesSinceDate:))]
366 #[unsafe(method_family = none)]
367 pub fn removeCachedResponsesSinceDate(&self, date: &NSDate);
368
369 /// In-memory capacity of the receiver.
370 ///
371 /// At the time this call is made, the in-memory cache will truncate its contents to the size given, if necessary.
372 ///
373 /// Returns: The in-memory capacity, measured in bytes, for the receiver.
374 #[unsafe(method(memoryCapacity))]
375 #[unsafe(method_family = none)]
376 pub fn memoryCapacity(&self) -> NSUInteger;
377
378 /// Setter for [`memoryCapacity`][Self::memoryCapacity].
379 #[unsafe(method(setMemoryCapacity:))]
380 #[unsafe(method_family = none)]
381 pub fn setMemoryCapacity(&self, memory_capacity: NSUInteger);
382
383 /// The on-disk capacity of the receiver.
384 ///
385 /// The on-disk capacity, measured in bytes, for the receiver. On mutation the on-disk cache will truncate its contents to the size given, if necessary.
386 #[unsafe(method(diskCapacity))]
387 #[unsafe(method_family = none)]
388 pub fn diskCapacity(&self) -> NSUInteger;
389
390 /// Setter for [`diskCapacity`][Self::diskCapacity].
391 #[unsafe(method(setDiskCapacity:))]
392 #[unsafe(method_family = none)]
393 pub fn setDiskCapacity(&self, disk_capacity: NSUInteger);
394
395 /// Returns the current amount of space consumed by the
396 /// in-memory cache of the receiver.
397 ///
398 /// This size, measured in bytes, indicates the current
399 /// usage of the in-memory cache.
400 ///
401 /// Returns: the current usage of the in-memory cache of the receiver.
402 #[unsafe(method(currentMemoryUsage))]
403 #[unsafe(method_family = none)]
404 pub fn currentMemoryUsage(&self) -> NSUInteger;
405
406 /// Returns the current amount of space consumed by the
407 /// on-disk cache of the receiver.
408 ///
409 /// This size, measured in bytes, indicates the current
410 /// usage of the on-disk cache.
411 ///
412 /// Returns: the current usage of the on-disk cache of the receiver.
413 #[unsafe(method(currentDiskUsage))]
414 #[unsafe(method_family = none)]
415 pub fn currentDiskUsage(&self) -> NSUInteger;
416 );
417}
418
419/// Methods declared on superclass `NSObject`.
420impl NSURLCache {
421 extern_methods!(
422 #[unsafe(method(init))]
423 #[unsafe(method_family = init)]
424 pub fn init(this: Allocated<Self>) -> Retained<Self>;
425
426 #[unsafe(method(new))]
427 #[unsafe(method_family = new)]
428 pub fn new() -> Retained<Self>;
429 );
430}
431
432impl DefaultRetained for NSURLCache {
433 #[inline]
434 fn default_retained() -> Retained<Self> {
435 Self::new()
436 }
437}
438
439/// NSURLSessionTaskAdditions.
440impl NSURLCache {
441 extern_methods!(
442 #[cfg(feature = "NSURLSession")]
443 #[unsafe(method(storeCachedResponse:forDataTask:))]
444 #[unsafe(method_family = none)]
445 pub fn storeCachedResponse_forDataTask(
446 &self,
447 cached_response: &NSCachedURLResponse,
448 data_task: &NSURLSessionDataTask,
449 );
450
451 #[cfg(all(feature = "NSURLSession", feature = "block2"))]
452 /// # Safety
453 ///
454 /// `completion_handler` block must be sendable.
455 #[unsafe(method(getCachedResponseForDataTask:completionHandler:))]
456 #[unsafe(method_family = none)]
457 pub unsafe fn getCachedResponseForDataTask_completionHandler(
458 &self,
459 data_task: &NSURLSessionDataTask,
460 completion_handler: &block2::DynBlock<dyn Fn(*mut NSCachedURLResponse)>,
461 );
462
463 #[cfg(feature = "NSURLSession")]
464 #[unsafe(method(removeCachedResponseForDataTask:))]
465 #[unsafe(method_family = none)]
466 pub fn removeCachedResponseForDataTask(&self, data_task: &NSURLSessionDataTask);
467 );
468}