• Stars
    star
    798
  • Rank 57,078 (Top 2 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created over 14 years ago
  • Updated over 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

URLCache subclass with on-disk cache support on iPhone/iPad

On iPhone OS, Apple did remove on-disk cache support for unknown reason. Some will say it's to save flash-drive life, others will arg it's to save disk capacity. As it is explained in the NSURLCacheStoragePolicy, the NSURLCacheStorageAllowed constant is always treated as NSURLCacheStorageAllowedInMemoryOnly and there is no way to force it back, the code is certainly gone on this platform. For whatever reason Apple removed this feature, you may be interested by having on-disk HTTP request caching in your application. SDURLCache gives back this feature to this iPhone OS for you.

To use it, you just have create an instance, replace the default shared NSURLCache with it and that's it, you instantly give on-disk HTTP request caching capability to your application.

SDURLCache *urlCache = [[SDURLCache alloc] initWithMemoryCapacity:1024*1024   // 1MB mem cache
                                                     diskCapacity:1024*1024*5 // 5MB disk cache
                                                         diskPath:[SDURLCache defaultCachePath]];
[NSURLCache setSharedURLCache:urlCache];
[urlCache release];

To save flash drive, SDURLCache doesn't cache on disk responses if cache expiration delay is lower than 5 minutes by default. You can change this behavior by changing the minCacheInterval property.

Cache eviction is done automatically when disk capacity is reached in a periodic maintenance thread. All disk write operations are done in a separated thread so they can't block the main run loop.

To control the caching behavior, use the NSURLRequest's cachePolicy property. If you want a response not to be cached on disk but still in memory, you can implement the NSURLConnection connection:willCacheResponse: delegate method and change the NSURLCachedResponse storagePolicy property to NSURLCacheStorageAllowedInMemoryOnly. See example below:

- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
                  willCacheResponse:(NSCachedURLResponse *)cachedResponse
{
    NSCachedURLResponse *memOnlyCachedResponse =
        [[NSCachedURLResponse alloc] initWithResponse:cachedResponse.response
                                                 data:cachedResponse.data
                                             userInfo:cachedResponse.userInfo
                                        storagePolicy:NSURLCacheStorageAllowedInMemoryOnly];
    return [memOnlyCachedResponse autorelease];
}

More Repositories

1

zerolog

Zero Allocation JSON Logger
Go
10,343
star
2

xid

xid is a globally unique id generator thought for the web
Go
3,874
star
3

curlie

The power of curl, the ease of use of httpie.
Go
2,808
star
4

cors

Go net/http configurable handler to handle CORS requests
Go
2,625
star
5

rest-layer

REST Layer, Go (golang) REST API framework
Go
1,257
star
6

SDSegmentedControl

A drop-in remplacement for UISegmentedControl that mimic iOS 6 AppStore tab controls
Objective-C
1,200
star
7

pushd

Blazing fast multi-protocol mobile and web push notification service
CoffeeScript
1,162
star
8

jplot

iTerm2 expvar/JSON monitoring tool
Go
1,140
star
9

SDAVAssetExportSession

AVAssetExportSession drop-in replacement with customizable audio&video settings
Objective-C
800
star
10

SafariTabSwitching

A SIMBL plugin for Safari 5.1 allowing tab switching by index (using Cmd-1, Cmd-2…)
Objective-C
472
star
11

jaggr

JSON Aggregation CLI
Go
460
star
12

SafariOmnibar

Safari plugin to add Chrome like omnibar in Safari
Objective-C
416
star
13

dnstrace

DNS resolution tracing tool
Go
270
star
14

dnscache

DNS lookup cache for Go
Go
267
star
15

node-netmask

Parse and lookup IP network blocks
CoffeeScript
253
star
16

xhandler

XHandler is a bridge between net/context and http.Handler
Go
233
star
17

xlog

xlog is a logger for net/context aware HTTP applications
Go
138
star
18

seamless

Seamless restart / zero-downtime deploy for Go servers
Go
107
star
19

xmux

xmux is a httprouter fork on top of xhandler (net/context aware)
Go
98
star
20

vast

Golang VAST 3.0 library
Go
83
star
21

xstats

xstats is a generic client for service instrumentation
Go
82
star
22

gls

A graphical ls command for iTerm2 with icons
Swift
78
star
23

SDNetworkActivityIndicator

Handle show/hiding of the iOS network activity indicator
Objective-C
75
star
24

zkfarmer

ZkFarmer is a set of tools to easily manage distributed server farms using Apache ZooKeeper
Python
74
star
25

logbench

Golang logging library benchmarks
Go
69
star
26

dashplay

Easy dashboard screen management
HTML
67
star
27

SDAdvancedWebView

Add some handy features to you UIWebViews
Objective-C
49
star
28

eve-auth-jwt

Eve OAuth 2.0 JWT token validation authentication module
Python
46
star
29

domcheck

A Python library to validate the ownership of a domain using different strategies
Python
45
star
30

iris-ice

Iris keyboard build with custom case
43
star
31

scanman

ScanSnap manager for Raspberry Pi
Python
40
star
32

formjson

Go net/http handler to transparently manage posted JSON
Go
39
star
33

moquette

MQTT service dispatcher
Go
38
star
34

SDReachability

Easy to use and to embed Reachability library
Objective-C
36
star
35

golp

Go panic logger
Go
27
star
36

xaccess

Go http handler access logger
Go
20
star
37

tzsp

TaZmen Sniffer Protocol (TZSP) parser in Go
Go
20
star
38

rest-layer-mongo

REST Layer MongoDB resource storage handler
Go
18
star
39

audience-meter

Lightweight server to mesure audience of a live event
JavaScript
17
star
40

node-dnsstamp

DNS Stamp encoding/decoding library for node
TypeScript
15
star
41

net-server-mail

Extensible Perl implementation of the STMP protocol and its different evolutions (ie: ESMTP, LMTP)
Perl
15
star
42

vmap

Golang VMAP 1.0 library
Go
14
star
43

SDSRTParser

Objective-C SRT subtitle parser
Objective-C
13
star
44

mysql-genocide

Parallel operations on MySQL processlist
Perl
11
star
45

dnsdump

DNS Packet Dump
Go
10
star
46

pinba_http

Pinba HTTP Gateway
Python
8
star
47

gh-readme

Githup pages template for projects README
CSS
7
star
48

rest-layer-es

REST Layer ElasticSearch resource storage handler
Go
6
star
49

mydbd

A mysqli OO interface with PEAR::DB API compatibility
PHP
5
star
50

local-ip

Go
4
star
51

rest-layer-mem

REST Layer memory storage handler
Go
4
star
52

homebrew-tap

rs homebrew packages
Ruby
3
star
53

xlog-nsq

XLog to NSQ Output
Go
3
star
54

rest-layer-hystrix

REST Layer Hystrix storage handler wrapper
Go
3
star
55

rrdpoller

Easily query and perform threshold tests on RRD files data
Perl
3
star
56

rrdcollect-remote

Collect rrdcollect output from several hosts to update local RRD files
Perl
2
star
57

SiriDailymotion

AssistantExtensions plugin to integrate Dailymotion to Siri on Jailbroken iPhone 4s
Objective-C
2
star
58

proxy

A simple HTTP explicit forward proxy http.Handler
Go
2
star
59

gcs-oauth2-boto-env-plugin

Google Storage auth2 plugin with support for passing service key via environment
Python
2
star
60

rs.github.com

1
star
61

obfu

Go
1
star