Inherits from NSObject
Declared in VKCache.h

Overview

Current class manages cached responses' data. Cached data are saved in directory which was selected during initialization process.

Tasks

Initialization methods

Methods to manage cached data

Getting cached data

  • – cacheForURL:

    Returns cached data by its URL, or nil, if life time of cached data has expired.

  • – cacheForURL:offlineMode:

    Returns cached data by its URL, or nil, if life time of cached data has expired or there is no data for current URL.

Instance Methods

addCache:forURL:

Current method adds new data to cached data directory

- (void)addCache:(NSData *)cache forURL:(NSURL *)url

Parameters

cache

data which should be cached

url

URL that corresponds to cached data

Discussion

Life time of current cached data defaults to one hour.

Declared In

VKCache.h

addCache:forURL:liveTime:

Current method adds new data to cached data directory

- (void)addCache:(NSData *)cache forURL:(NSURL *)url liveTime:(VKCacheLiveTime)cacheLiveTime

Parameters

cache

data which should be cached

url

URL that corresponds to cached data

cacheLiveTime

life time of current cached data (possible values: VKCacheLiveTimeOneHour, VKCacheLiveTimeOneDay, VKCacheLiveTimeForever etc).

Declared In

VKCache.h

cacheForURL:

Returns cached data by its URL, or nil, if life time of cached data has expired.

- (NSData *)cacheForURL:(NSURL *)url

Parameters

url

URL that corresponds to cached data

Return Value

instance of NSData class, cached data

Declared In

VKCache.h

cacheForURL:offlineMode:

Returns cached data by its URL, or nil, if life time of cached data has expired or there is no data for current URL.

- (NSData *)cacheForURL:(NSURL *)url offlineMode:(BOOL)offlineMode

Parameters

url

URL that corresponds to cached data

offlineMode

offline mode

Return Value

instance of NSData class, cached data which corresponds to received URL

Discussion

As you know, offlineMode can make current method return cached data even if its life time expired. You should use offlineMode (YES) if there is no internet connection.

Declared In

VKCache.h

clear

Removes all cached data in a directory which were used for initialization.

- (void)clear

Declared In

VKCache.h

initWithCacheDirectory:

Initialization methods

- (instancetype)initWithCacheDirectory:(NSString *)path

Parameters

path

directory where would be saved cached data. If there is no such directory then it’s going to be created.

Return Value

instance of VKCache

Declared In

VKCache.h

removeCacheDirectory

Removes directory with all cached data.

- (void)removeCacheDirectory

Declared In

VKCache.h

removeCacheForURL:

Removes cached data by its URL

- (void)removeCacheForURL:(NSURL *)url

Parameters

url

URL that corresponds to cached data which needs to be removed

Declared In

VKCache.h