Lily 是一个轻量级的 Swift 缓存框架。
不建议手动安装框架,但如果您更喜欢不使用上述依赖管理器中的一种,您可以手动将 Lily 集成到项目中。在您的项目中使用 Lily 的常规方式是使用嵌入式框架。
cd
到顶级项目目录,并输入以下命令$ git submodule add https://github.com/kukushi/Lily.git
Lily
文件夹,并将 Lily.xcodeproj
拖放到应用项目文件导航器下,在您的应用项目下。Lily.framework
。+
按钮并选择“New Copy Files Phase”,将此新阶段重命名为“Copy Frameworks”,将“目标”设置为“Frameworks”,并添加 Lily.framework
。内存级别的内存缓存。当应用终止时,所有内容都将消失。
// Save integer 1 with key "poi" in the default context using the memory cache
MemoryCache["poi"] = 1
// Retrive the content with key "poi" in the default context from the memory cache
let poi = MemoryCache["poi"].intValue
// If you want to do something in other context, just add other key.
// Save string "hey" with "poi" key in the "You" context
MemoryCache["poi", "You"] = "hey"
// retrive the content of "poi" key in the "You" context
let poiYou = MemoryCache["poi", "You"].stringValue
MemoryCache
在内存级别工作。当应用终止时,所有内容都将被移除。
QuickCache
基于 MemoryCache
。它会在正确的时间将所有内容写入磁盘。
DiskCache
也基于 MemoryCache
。每次修改带键的内容时,它都会执行磁盘级别缓存。
Lily 是根据 MIT 许可发布的。有关详细信息,请参阅 LICENSE。