Swiftpack.co - colddream/LRUCache as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by colddream.
colddream/LRUCache 1.0.0
LRUCache
⭐️ 0
🕓 1 year ago
iOS
.package(url: "https://github.com/colddream/LRUCache.git", from: "1.0.0")

Introduction

LRUCache is an open-source replacement for NSCache that behaves in a predictable, debuggable way. LRUCache is an LRU (Least-Recently-Used) cache, meaning that objects will be discarded oldest-first based on the last time they were accessed. LRUCache will automatically empty itself in the event of a memory warning.

Installation

LRUCache is packaged as a dynamic framework that you can import into your Xcode project. You can install this manually, or by using Swift Package Manager.

Note: LRUCache requires Xcode 13+ to build, and runs on iOS 11+.

To install using Swift Package Manage, add this to the dependencies: section in your Package.swift file:

.package(url: "https://github.com/colddream/LRUCache", .upToNextMinor(from: "1.0.0")),

Usage

You can create an instance of LRUCache as follows:

let cache = LRUCache<String, Int>(capacity: capacity)

This would create a cache of unlimited size, containing Int values keyed by String. To add a value to the cache, use:

cache.set(value: 11, for: "Key1")

To fetch a cached value, use:

let value = cache.getValue(for: "Key1") // Returns nil if value not found

And you can remove all values at once with:

cache.removeAll()

GitHub

link
Stars: 0
Last commit: 1 year ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.0.0
11 weeks ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics