Skip to content

Commit

Permalink
cache restore alternative
Browse files Browse the repository at this point in the history
Added an option for alternative cache response
  • Loading branch information
evermeer committed Feb 3, 2016
1 parent 7c4e2c7 commit 4d5fdb5
Show file tree
Hide file tree
Showing 42 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion EVURLCache.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Pod::Spec.new do |s|
#

s.name = "EVURLCache"
s.version = "2.2.1"
s.version = "2.3.0"
s.summary = "NSURLCache subclass for handeling all web requests that use NSURLRequest"
s.description = "This is a NSURLCache subclass for handeling all web requests that use NSURLRequest. (This includes UIWebView)"
s.homepage = "https://github.com/evermeer/EVURLCache"
Expand Down
4 changes: 2 additions & 2 deletions EVURLCache.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -464,7 +464,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 9.1;
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down
2 changes: 1 addition & 1 deletion EVURLCache/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
EVURLCache.FORCE_LOWERCASE = true // is already the default. You also have to put all files int he PreCache using lowercase names
// Now activate this cache
EVURLCache.activate()

NSLog("Cache is now active")
return true
}

Expand Down
13 changes: 12 additions & 1 deletion EVURLCache/Pod/EVURLCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ public class EVURLCache : NSURLCache {
public static var FORCE_LOWERCASE = true // Set this to false if you want to use case insensitive filename compare
public static var _cacheDirectory: String!
public static var _preCacheDirectory: String!

public static var RECREATE_CACHE_RESPONSE = true // There is a difrence between unarchiving and recreating. I have to find out what.

// Activate EVURLCache
public class func activate() {
// set caching paths
Expand Down Expand Up @@ -102,7 +103,17 @@ public class EVURLCache : NSURLCache {
// Read object from file
if let response = NSKeyedUnarchiver.unarchiveObjectWithFile(storagePath) as? NSCachedURLResponse {
EVURLCache.debugLog("Returning cached data from \(storagePath)");

// I have to find out the difrence. For now I will let the developer checkt which version to use
if EVURLCache.RECREATE_CACHE_RESPONSE {
// This works for most sites, but aperently not for the game as in the alternate url you see in ViewController
let r = NSURLResponse(URL: response.response.URL!, MIMEType: response.response.MIMEType, expectedContentLength: response.data.length, textEncodingName: response.response.textEncodingName)
return NSCachedURLResponse(response: r, data: response.data, userInfo: response.userInfo, storagePolicy: .Allowed)
}
// This works for the game, but not for my site.
return response
} else {
EVURLCache.debugLog("The file is probably not put in the local path using NSKeyedArchiver \(storagePath)");
}
return nil
}
Expand Down
5 changes: 4 additions & 1 deletion EVURLCache/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ class ViewController: UIViewController {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

// An other nice test url is: http://game.zorropk.com/gamenow/xiao5haiyanglixianji/
// Uncomment the 2 lines below and comment the line below that to see an other nice test
// EVURLCache.RECREATE_CACHE_RESPONSE = false
// if let url = NSURL(string: "http://game.zorropk.com/gamenow/xiao5haiyanglixianji/") {
if let url = NSURL(string: "http://evict.nl") {
NSLog("navigating to \(url)")
webView.loadRequest(NSURLRequest(URL: url))
}
}
Expand Down
Binary file added PreCache/evict.nl/edwin_vermeer/status/index.html
Binary file not shown.
Binary file modified PreCache/evict.nl/index.html
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PreCache/evict.nl/wp-content/plugins/jetpack/_inc/jquery.spin.js
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-content/plugins/jetpack/_inc/spin.js
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-content/plugins/jetpack/css/jetpack.css
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-content/plugins/jetpack/modules/wpgroho.js
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-content/themes/limelight/js/navigation.js
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-content/themes/limelight/style.css
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-content/uploads/2015/02/sunrise.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PreCache/evict.nl/wp-content/uploads/2015/02/sunset.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PreCache/evict.nl/wp-content/uploads/2015/02/sunset1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PreCache/evict.nl/wp-content/uploads/2015/02/sunset4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PreCache/evict.nl/wp-includes/js/jquery/jquery-migrate.min.js
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-includes/js/jquery/jquery.js
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-includes/js/mediaelement/wp-mediaelement.js
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-includes/js/tw-sack.min.js
Binary file not shown.
Binary file added PreCache/evict.nl/wp-includes/js/wp-embed.min.js
Binary file not shown.
Binary file modified PreCache/evict.nl/wp-includes/js/wp-emoji-release.min.js
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4d5fdb5

Please sign in to comment.