测试已测试 | ✗ |
语言语言 | SwiftSwift |
许可证 | MIT |
发布最新发布 | 2017年3月 |
SwiftSwift 版本 | 3.0 |
SPM支持 SPM | ✗ |
由 Ben Bahrenburg 维护。
需要缓存?注重安全性?BucketList 使得处理加密缓存变得容易。同时也支持标准键值缓存。
LockedBucket 通过 CocoaPods 提供使用。要安装它,只需将以下行添加到您的 Podfile 中:
pod "BucketList"
手动
将 BucketList/Classes/
目录中的所有 *.swift
文件复制到您的项目中。
BucketList 中有六个主要类
所有缓存提供者都有一个类似的 API,唯一的区别是安全协议中使用的密钥字段。
BucketList 使得将项目存储到缓存变得很简单。以下是如何使用 EncryptedDiskCache 来做的示例。
//Let's create an instance of the EncryptedDiskCache provider
//The first things we need to do is create a caching name. This will be the folder the files are cached within.
let cache = EncryptedDiskCache(cacheName: "foo")
//Now let's add a image to cache
let myImage = .....
let result = cache.add(secret: "a password", forKey: "my-secret-image", image: myImage)
print("Image was successfull added? \(result)")
//Now let's add a AnyObject to cache
let myObject = .....
let result = cache.add(secret: "a password", forKey: "my-secret-object", object: myObject)
print("myObject was successfull added? \(result)")
//Now let's add a Data to cache
let myData = .....
let result = cache.add(secret: "a password", forKey: "my-secret-data", data: myData)
print("myData was successfull added? \(result)")
您可以从缓存中轻松地获取项目。以下是如何使用 EncryptedDiskCache 来做到这一点的示例。
//Let's create an instance of the EncryptedDiskCache provider
//The first things we need to do is create a caching name. This will be the folder the files are cached within.
let cache = EncryptedDiskCache(cacheName: "foo")
//Let's get our image from cache
let myImage = cache.getImage(secret: "a password", forKey: "my-secret-image")
//Now let's get our AnyObject from cache
let myObject = cache.getObject(secret: "a password", forKey: "my-secret-object")
print("myObject was successfull added? \(result)")
//Now let's get our Data from cache
let myData = cache.getData(secret: "a password", forKey: "my-secret-data")
您可以使用 exist 函数轻松检查项目是否已在缓存中。以下是使用 EncryptedDiskCache 完成此操作的示例。
//Let's create an instance of the EncryptedDiskCache provider
//The first things we need to do is create a caching name. This will be the folder the files are cached within.
let cache = EncryptedDiskCache(cacheName: "foo")
let isThere = cache.exists(forKey: "my-secret-image")
print("Is my image already in cache? \(isThere)")
您还可以从缓存中移除项目。以下是使用 EncryptedDiskCache 完成此操作的示例。
//Let's create an instance of the EncryptedDiskCache provider
//The first things we need to do is create a caching name. This will be the folder the files are cached within.
let cache = EncryptedDiskCache(cacheName: "foo")
let wasRemoved = cache.remove(forKey: "my-secret-image")
print("Is my image was removed from cache? \(wasRemoved)")
您可以轻松地清空所有的缓存项目。以下是使用 EncryptedDiskCache 完成此操作的示例。
//Let's create an instance of the EncryptedDiskCache provider
//The first things we need to do is create a caching name. This will be the folder the files are cached within.
let cache = EncryptedDiskCache(cacheName: "foo")
let allRemoved = cache.empty()
print("All items removed from cache? \(allRemoved)")
Ben Bahrenburg,@bencoding
LockedBucket 在 MIT 许可证下可用。请参阅 LICENSE 文件以获取更多信息。