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 unsafe 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        #[unsafe(method(initWithResponse:data:userInfo:storagePolicy:))]
130        #[unsafe(method_family = init)]
131        pub unsafe fn initWithResponse_data_userInfo_storagePolicy(
132            this: Allocated<Self>,
133            response: &NSURLResponse,
134            data: &NSData,
135            user_info: Option<&NSDictionary>,
136            storage_policy: NSURLCacheStoragePolicy,
137        ) -> Retained<Self>;
138
139        #[cfg(feature = "NSURLResponse")]
140        /// Returns the response wrapped by this instance.
141        ///
142        /// Returns: The response wrapped by this instance.
143        #[unsafe(method(response))]
144        #[unsafe(method_family = none)]
145        pub unsafe fn response(&self) -> Retained<NSURLResponse>;
146
147        #[cfg(feature = "NSData")]
148        /// Returns the data of the receiver.
149        ///
150        /// Returns: The data of the receiver.
151        #[unsafe(method(data))]
152        #[unsafe(method_family = none)]
153        pub unsafe fn data(&self) -> Retained<NSData>;
154
155        #[cfg(feature = "NSDictionary")]
156        /// Returns the userInfo dictionary of the receiver.
157        ///
158        /// Returns: The userInfo dictionary of the receiver.
159        #[unsafe(method(userInfo))]
160        #[unsafe(method_family = none)]
161        pub unsafe fn userInfo(&self) -> Option<Retained<NSDictionary>>;
162
163        /// Returns the NSURLCacheStoragePolicy constant of the receiver.
164        ///
165        /// Returns: The NSURLCacheStoragePolicy constant of the receiver.
166        #[unsafe(method(storagePolicy))]
167        #[unsafe(method_family = none)]
168        pub unsafe fn storagePolicy(&self) -> NSURLCacheStoragePolicy;
169    );
170}
171
172/// Methods declared on superclass `NSObject`.
173impl NSCachedURLResponse {
174    extern_methods!(
175        #[unsafe(method(init))]
176        #[unsafe(method_family = init)]
177        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
178
179        #[unsafe(method(new))]
180        #[unsafe(method_family = new)]
181        pub unsafe fn new() -> Retained<Self>;
182    );
183}
184
185extern_class!(
186    /// [Apple's documentation](https://developer.apple.com/documentation/foundation/nsurlcache?language=objc)
187    #[unsafe(super(NSObject))]
188    #[derive(Debug, PartialEq, Eq, Hash)]
189    pub struct NSURLCache;
190);
191
192unsafe impl Send for NSURLCache {}
193
194unsafe impl Sync for NSURLCache {}
195
196extern_conformance!(
197    unsafe impl NSObjectProtocol for NSURLCache {}
198);
199
200impl NSURLCache {
201    extern_methods!(
202        /// Returns the shared NSURLCache instance or
203        /// sets the NSURLCache instance shared by all clients of
204        /// the current process. This will be the new object returned when
205        /// calls to the
206        /// <tt>
207        /// sharedURLCache
208        /// </tt>
209        /// method are made.
210        ///
211        /// Unless set explicitly through a call to
212        /// <tt>
213        /// +setSharedURLCache:
214        /// </tt>
215        /// , this method returns an NSURLCache
216        /// instance created with the following default values:
217        /// <ul>
218        /// <li>
219        /// Memory capacity: 4 megabytes (4 * 1024 * 1024 bytes)
220        /// <li>
221        /// Disk capacity: 20 megabytes (20 * 1024 * 1024 bytes)
222        /// <li>
223        /// Disk path:
224        /// <nobr
225        /// >(user home directory)/Library/Caches/(application bundle id)
226        /// </nobr
227        /// >
228        /// </ul>
229        /// <p>
230        /// Users who do not have special caching requirements or
231        /// constraints should find the default shared cache instance
232        /// acceptable. If this default shared cache instance is not
233        /// acceptable,
234        /// <tt>
235        /// +setSharedURLCache:
236        /// </tt>
237        /// can be called to set a
238        /// different NSURLCache instance to be returned from this method.
239        /// Callers should take care to ensure that the setter is called
240        /// at a time when no other caller has a reference to the previously-set
241        /// shared URL cache. This is to prevent storing cache data from
242        /// becoming unexpectedly unretrievable.
243        ///
244        /// Returns: the shared NSURLCache instance.
245        #[unsafe(method(sharedURLCache))]
246        #[unsafe(method_family = none)]
247        pub unsafe fn sharedURLCache() -> Retained<NSURLCache>;
248
249        /// Setter for [`sharedURLCache`][Self::sharedURLCache].
250        #[unsafe(method(setSharedURLCache:))]
251        #[unsafe(method_family = none)]
252        pub unsafe fn setSharedURLCache(shared_url_cache: &NSURLCache);
253
254        #[cfg(feature = "NSString")]
255        /// Initializes an NSURLCache with the given capacity and
256        /// path.
257        ///
258        /// The returned NSURLCache is backed by disk, so
259        /// developers can be more liberal with space when choosing the
260        /// capacity for this kind of cache. A disk cache measured in the tens
261        /// of megabytes should be acceptable in most cases.
262        ///
263        /// Parameter `memoryCapacity`: the capacity, measured in bytes, for the cache in memory.
264        ///
265        /// Parameter `diskCapacity`: the capacity, measured in bytes, for the cache on disk.
266        ///
267        /// Parameter `path`: the path on disk where the cache data is stored.
268        ///
269        /// Returns: an initialized NSURLCache, with the given capacity, backed
270        /// by disk.
271        #[deprecated]
272        #[unsafe(method(initWithMemoryCapacity:diskCapacity:diskPath:))]
273        #[unsafe(method_family = init)]
274        pub unsafe fn initWithMemoryCapacity_diskCapacity_diskPath(
275            this: Allocated<Self>,
276            memory_capacity: NSUInteger,
277            disk_capacity: NSUInteger,
278            path: Option<&NSString>,
279        ) -> Retained<Self>;
280
281        #[cfg(feature = "NSURL")]
282        /// Initializes an NSURLCache with the given capacity and directory.
283        ///
284        /// Parameter `memoryCapacity`: the capacity, measured in bytes, for the cache in memory. Or 0 to disable memory cache.
285        ///
286        /// Parameter `diskCapacity`: the capacity, measured in bytes, for the cache on disk. Or 0 to disable disk cache.
287        ///
288        /// Parameter `directoryURL`: the path to a directory on disk where the cache data is stored. Or nil for default directory.
289        ///
290        /// Returns: an initialized NSURLCache, with the given capacity, optionally backed by disk.
291        #[unsafe(method(initWithMemoryCapacity:diskCapacity:directoryURL:))]
292        #[unsafe(method_family = init)]
293        pub unsafe fn initWithMemoryCapacity_diskCapacity_directoryURL(
294            this: Allocated<Self>,
295            memory_capacity: NSUInteger,
296            disk_capacity: NSUInteger,
297            directory_url: Option<&NSURL>,
298        ) -> Retained<Self>;
299
300        #[cfg(feature = "NSURLRequest")]
301        /// Returns the NSCachedURLResponse stored in the cache with
302        /// the given request.
303        ///
304        /// The method returns nil if there is no
305        /// NSCachedURLResponse stored using the given request.
306        ///
307        /// Parameter `request`: the NSURLRequest to use as a key for the lookup.
308        ///
309        /// Returns: The NSCachedURLResponse stored in the cache with the given
310        /// request, or nil if there is no NSCachedURLResponse stored with the
311        /// given request.
312        #[unsafe(method(cachedResponseForRequest:))]
313        #[unsafe(method_family = none)]
314        pub unsafe fn cachedResponseForRequest(
315            &self,
316            request: &NSURLRequest,
317        ) -> Option<Retained<NSCachedURLResponse>>;
318
319        #[cfg(feature = "NSURLRequest")]
320        /// Stores the given NSCachedURLResponse in the cache using
321        /// the given request.
322        ///
323        /// Parameter `cachedResponse`: The cached response to store.
324        ///
325        /// Parameter `request`: the NSURLRequest to use as a key for the storage.
326        #[unsafe(method(storeCachedResponse:forRequest:))]
327        #[unsafe(method_family = none)]
328        pub unsafe fn storeCachedResponse_forRequest(
329            &self,
330            cached_response: &NSCachedURLResponse,
331            request: &NSURLRequest,
332        );
333
334        #[cfg(feature = "NSURLRequest")]
335        /// Removes the NSCachedURLResponse from the cache that is
336        /// stored using the given request.
337        ///
338        /// No action is taken if there is no NSCachedURLResponse
339        /// stored with the given request.
340        ///
341        /// Parameter `request`: the NSURLRequest to use as a key for the lookup.
342        #[unsafe(method(removeCachedResponseForRequest:))]
343        #[unsafe(method_family = none)]
344        pub unsafe fn removeCachedResponseForRequest(&self, request: &NSURLRequest);
345
346        /// Clears the given cache, removing all NSCachedURLResponse
347        /// objects that it stores.
348        #[unsafe(method(removeAllCachedResponses))]
349        #[unsafe(method_family = none)]
350        pub unsafe fn removeAllCachedResponses(&self);
351
352        #[cfg(feature = "NSDate")]
353        /// Clears the given cache of any cached responses since the provided date.
354        #[unsafe(method(removeCachedResponsesSinceDate:))]
355        #[unsafe(method_family = none)]
356        pub unsafe fn removeCachedResponsesSinceDate(&self, date: &NSDate);
357
358        /// In-memory capacity of the receiver.
359        ///
360        /// At the time this call is made, the in-memory cache will truncate its contents to the size given, if necessary.
361        ///
362        /// Returns: The in-memory capacity, measured in bytes, for the receiver.
363        #[unsafe(method(memoryCapacity))]
364        #[unsafe(method_family = none)]
365        pub unsafe fn memoryCapacity(&self) -> NSUInteger;
366
367        /// Setter for [`memoryCapacity`][Self::memoryCapacity].
368        #[unsafe(method(setMemoryCapacity:))]
369        #[unsafe(method_family = none)]
370        pub unsafe fn setMemoryCapacity(&self, memory_capacity: NSUInteger);
371
372        /// The on-disk capacity of the receiver.
373        ///
374        /// 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.
375        #[unsafe(method(diskCapacity))]
376        #[unsafe(method_family = none)]
377        pub unsafe fn diskCapacity(&self) -> NSUInteger;
378
379        /// Setter for [`diskCapacity`][Self::diskCapacity].
380        #[unsafe(method(setDiskCapacity:))]
381        #[unsafe(method_family = none)]
382        pub unsafe fn setDiskCapacity(&self, disk_capacity: NSUInteger);
383
384        /// Returns the current amount of space consumed by the
385        /// in-memory cache of the receiver.
386        ///
387        /// This size, measured in bytes, indicates the current
388        /// usage of the in-memory cache.
389        ///
390        /// Returns: the current usage of the in-memory cache of the receiver.
391        #[unsafe(method(currentMemoryUsage))]
392        #[unsafe(method_family = none)]
393        pub unsafe fn currentMemoryUsage(&self) -> NSUInteger;
394
395        /// Returns the current amount of space consumed by the
396        /// on-disk cache of the receiver.
397        ///
398        /// This size, measured in bytes, indicates the current
399        /// usage of the on-disk cache.
400        ///
401        /// Returns: the current usage of the on-disk cache of the receiver.
402        #[unsafe(method(currentDiskUsage))]
403        #[unsafe(method_family = none)]
404        pub unsafe fn currentDiskUsage(&self) -> NSUInteger;
405    );
406}
407
408/// Methods declared on superclass `NSObject`.
409impl NSURLCache {
410    extern_methods!(
411        #[unsafe(method(init))]
412        #[unsafe(method_family = init)]
413        pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
414
415        #[unsafe(method(new))]
416        #[unsafe(method_family = new)]
417        pub unsafe fn new() -> Retained<Self>;
418    );
419}
420
421/// NSURLSessionTaskAdditions.
422impl NSURLCache {
423    extern_methods!(
424        #[cfg(feature = "NSURLSession")]
425        #[unsafe(method(storeCachedResponse:forDataTask:))]
426        #[unsafe(method_family = none)]
427        pub unsafe fn storeCachedResponse_forDataTask(
428            &self,
429            cached_response: &NSCachedURLResponse,
430            data_task: &NSURLSessionDataTask,
431        );
432
433        #[cfg(all(feature = "NSURLSession", feature = "block2"))]
434        #[unsafe(method(getCachedResponseForDataTask:completionHandler:))]
435        #[unsafe(method_family = none)]
436        pub unsafe fn getCachedResponseForDataTask_completionHandler(
437            &self,
438            data_task: &NSURLSessionDataTask,
439            completion_handler: &block2::DynBlock<dyn Fn(*mut NSCachedURLResponse)>,
440        );
441
442        #[cfg(feature = "NSURLSession")]
443        #[unsafe(method(removeCachedResponseForDataTask:))]
444        #[unsafe(method_family = none)]
445        pub unsafe fn removeCachedResponseForDataTask(&self, data_task: &NSURLSessionDataTask);
446    );
447}