Latest 0.0.2
License MIT
Platforms ios 6.0, requires ARC
Dependencies NSData+MD5Digest, TMCache, Parse-iOS-SDK


NOTE: This repo is no longer maintained. We ended up abandoning Parse because of performance and security issues.

This category on PFCloud adds an additional cachePolicy parameter to Parse’s existing asynchronous (background) cloud function call methods. It exactly replicates the existing caching behavior used with the PFQuery object. It creates a record in the cache for every unique combination of function name + parameters.

+ (void)callFunctionInBackground:(NSString*)function
+ (void)callFunctionInBackground:(NSString*)function

Sample Usage

#import "PFCloud+Cache.h"

[PFCloud callFunctionInBackground:function
                            block:^(id object, NSError* error) {
        //Because we are using kPFCachePolicyCacheThenNetwork as our cache policy,
        //this block will be invoked twice (if a cached result exists). 


Both the contents of the parameters dictionary and the cloud function return value must conform to the NSCoding protocol. Note that PFObject does not conform to NSCoding by default. If your cloud function returns one or more PFObjects, you must implement this protocol yourself or use my other Parse+NSCoding library.

Cache Management

Cached objects are persisted to disk in the following folder on the user’s device:


Cached objects persist between app restarts until they expire. By default they never expire. To impose a maximum cache age use the setMaxCacheAge: method. The cache can also be explicity cleared for a particular cloud function call using the clearCachedResult: method, or for all calls using the clearAllCachedResults method.

How it Works

The trick is to create a unique key in the cache for every unique combination of function + parameters. This library serializes the function name along with the contents of the parameters dictionary. It then calculates a MD5 hex digest using the NSData-MD5 library to create a unique string key for the cache. Actual caching is performed using Tumblr’s TMCache library. Thanks to those libraries for their great work!


Easiest installation is using CocoaPods to resolve all dependencies:

pod 'PFCloud+Cache', '~> 0.0.2'

Otherwise you must manually copy the .h and .m files from this repo as well as from NSData-MD5 and TMCache. Obviously you must also have the Parse SDK installed. Enjoy!

Latest podspec

    "name": "PFCloud+Cache",
    "version": "0.0.2",
    "summary": "iOS library for caching cloud function calls in Parse.",
    "homepage": "",
    "license": {
        "type": "MIT"
    "authors": {
        "Martin Rybak": "[email protected]"
    "source": {
        "git": "",
        "tag": "0.0.2"
    "platforms": {
        "ios": "6.0"
    "source_files": "*.{h,m}",
    "requires_arc": true,
    "dependencies": {
        "NSData+MD5Digest": [
            "~> 1.0"
        "TMCache": [
            "~> 1.2.0"
        "Parse-iOS-SDK": [
            "~> 1.2.18"
    "xcconfig": {

Pin It on Pinterest

Share This