/AFCache

AFCache is an HTTP cache for use on iPhone/iPad seeking towards full RFC2616 compliance

Primary LanguageC

WHAT IS AFCACHE?
---
AFCache is an HTTP disk and in-memory cache for use on iPhone/iPad and OSX.
It can be linked as a static library or as a framework.

Goals:

 - Build a fully RFC2616 compliant cache instead of doing simple time-based caching
 - Provide an offline mode to deliver content from cache when no network is available 
 - Provide a packaging mechanism to pre-populate the cache for accessing content offline
 - Allow caching of UIWebView resources by overriding NSURLCache

CURRENT VERSION
---
0.6.6

PROJECT STATUS
---
AFCache is used in several iPhone applications in several versions. It is constantly evolving and
therefore considered beta/unstable. Currently I am doing some major changes and additions like
a packaging tool and testing it on two large real-world projects (iPhone and OSX apps). After 
sucessfully integrating AFCache into these projects I'll extend the demos and some documentation to
make it a useful library for the public.

KNOWN ISSUES
---
- Package file handling strategy not completely clear. Right now, a package is removed right after extracting. One might want to track which packages have been extracted yet. This also has to play nice with the file displacement strategy.
- Big file should be streamed to disk directly instead of holding them in an AFCacheableItem in memory.
- still very unhappy with the cleanup method. Need a clever displacement algorithm here.
- the code to determine cache file size on disk is commented out, because there's a bug in it. Don't use this release for production.
- synchronized requests are not testet well
- instead of using a php script for the server part, an integrated http server for unit testing might be better. Maybe also mock objects for NSResponse objects could do it.
- Maybe the mimetype should be added to the manifest file?
- Make encryption optional. Right now, there's encryption code in the zip classes.
- Xcode Bug (?): If you switch from an OSX target (e.g. afcpkg) to an iOS target, e.g. the demo app, switchig back doesn't work for me. Xcode always complaints: target specifies product type 'com.apple.product-type.tool', but there's no such product type for the 'iphonesimulator' platform
I only can get it running again when I remove line

activeSDKPreference = iphonesimulator3.2; (or similar, in section "/* Project object */")

If you have a solution, let me know.

ANATOMY OF THE MANIFEST FILE
---

The afcache.manifest file contains an entry for every file contained in the archive. One entry looks like this:

URL ; last-modified ; expires\n

Note the delimiter, which is " ; " (space semikolon space)

Example:

http://upload.wikimedia.org/wikipedia/commons/6/63/Wikipedia-logo.png ; Sat, 27 Mar 2004 18:43:30 GMT+00:00 ; Thu, 29 Jul 2010 14:17:20 GMT+00:00

The URL MUST ne properly encoded and MUST NOT contain a hash at the end or parameters.

Since the file path is calculated based on the URL, it's not necessary to include it in the manifest file.
The dates have to be formatted according to rfc1123. Example: "Wed, 01 Mar 2006 12:00:00 GMT"

ANATOMY OF THE PACKAGE ZIP FILE
---
The zip file structure resembles the URL:

hostname/path/to/file.suffix


BUILD NOTES FOR YOUR PROJECT THAT IS USING AFCACHE
---
You need to link to SystemConfiguration.framework and libz.dylib to compile.
Since AFCache uses Objective-C Categories, you need to add the following options to the linker (Targets/YourProject, Info, Build Settings: "Other linker flags")
-ObjC
-all_load

For more information see: http://developer.apple.com/mac/library/qa/qa2006/qa1490.html


HOW TO RUN THE UNIT TESTS
---
The unit tests currently depend on an existing HTTP-Server e.g. Apache. A simple php script
is provided to answer the requests properly. Put the script on your htdocs directory and
configure the URL in LogicTests.m, e.g.

static NSString *kBaseURL = @"http://127.0.0.1/~mic/afcache/";

For more information see CHANGES.

I am frequently using Charles as an HTTP debugging proxy which is superb for finding irregularities.
http://www.charlesproxy.com/


COPYRIGHT
---
Copyright 2008, 2009, 2010 Artifacts - Fine Software Development
http://www.artifacts.de
Author: Michael Markowski, Artifacts (m.markowski@artifacts.de)
Contributors: Nico Schmidt, Savoy Software

LICENSE
--- 
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.