XHNetworkCache is a powerful and lightweight caching library for iOS, designed to enhance network data caching capabilities in your app. With XHNetworkCache, you can easily cache and retrieve network responses, improving performance and user experience.

Key Features

  • Efficient caching of network responses
  • Simple API for caching and retrieving data
  • Supports both memory and disk caching
  • Customizable cache expiration policies
  • Automatic cache management
  • Easy integration with existing networking libraries


To integrate XHNetworkCache into your iOS project, you can use CocoaPods or manually add the library files.


To install XHNetworkCache using CocoaPods, add the following line to your Podfile:

pod 'XHNetworkCache'

Then run the command:

pod install

Manual Installation

Alternatively, you can manually add the XHNetworkCache library files to your project by following these steps:

  1. Download the latest version of XHNetworkCache from the GitHub repository.
  2. Drag and drop the XHNetworkCache folder into your Xcode project.
  3. Ensure that “Copy items if needed” is selected.
  4. Make sure the library files are added to your target’s “Build Phases” -> “Compile Sources” list.
  5. You’re ready to start using XHNetworkCache in your project!


Using XHNetworkCache is straightforward. Simply import the library and make use of its API methods to cache and retrieve network responses.

Caching a Response

To cache a network response, use the following code snippet:

  // Assuming you have a network response object called "response"
  [[XHNetworkCache sharedCache] cacheData:response forKey:@"responseKey"];

Retrieving a Cached Response

To retrieve a cached network response, use the following code snippet:

  // Assuming you want to retrieve the response with key "responseKey"
  id cachedResponse = [[XHNetworkCache sharedCache] cachedDataForKey:@"responseKey"];

Customizing Expiration Policies

XHNetworkCache allows you to customize expiration policies for cached responses. By default, it uses a time-based expiration policy.

To customize the expiration policy, implement the XHNetworkCacheDelegate protocol and configure the expiration interval for each cache key. For example:

  // Make your class conform to XHNetworkCacheDelegate
  // ...
  // Inside your implementation, set the expiration interval for a specific key
  - (NSTimeInterval)networkCache:(XHNetworkCache *)cache expirationIntervalForKey:(NSString *)key {
    if ([key isEqualToString:@"responseKey"]) {
      return 3600; // 1 hour expiration
    return -1; // Use the default expiration interval


XHNetworkCache provides a reliable and efficient caching solution for iOS app developers. By seamlessly integrating it into your project, you can leverage its caching capabilities to optimize network requests and improve user experience. Start using XHNetworkCache today and experience the benefits of enhanced network data caching in your app.