Skip to content

This cache could download and hold any type of data. Cache size could be explicitly defined. Since it uses NSCache, out of memory situations are gracefully handled.

License

Notifications You must be signed in to change notification settings

Tulakshana/FileCache

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Introduction

This cache could download and hold any type of data. Cache size could be explicitly defined. Since it uses NSCache, out of memory situations are also gracefully handled.

Demo

For first-hand experience, just open the sample project and run it.

Installation

Copy cache folder to your project. That's it.

Usage

Request the file by specifying the url

FileCache.sharedInstance.fetchFileForURL(urlString: "the-url-you-request")

Subscribe to notifications

NotificationCenter.default.addObserver(self, selector: #selector(didReceiveFileCacheDidDownloadFile(notification:)), name: Notification.Name.init(rawValue: notificationFileCacheDidDownloadFile), object: nil)

Handle notification

If you have multiple requests initiated check the urlString property in the returned object to verify the notification.

    @objc func didReceiveFileCacheDidDownloadFile(notification: Notification) {
        if let cachedFile: FCFile = notification.object as? FCFile {
            if cachedFile.urlString == "the-url-you-requested" {
                if let data: NSData = cachedFile.fileData {
                    //Do something with the data received
                }
            }
        }
    }

Clearing cache

FileCache.sharedInstance.clearCacheForURL(urlString: "your-url")

Setting cache size

FileCache.sharedInstance.maxCacheSize = 10.0 //size in mega bytes

License

The MIT License (MIT)

About

This cache could download and hold any type of data. Cache size could be explicitly defined. Since it uses NSCache, out of memory situations are gracefully handled.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published