Releases: 0xLeif/Cache
2.1.2
2.1.1
What's Changed
- Update windows.yml by @0xLeif in #17
- Update for Swift 6 with thread safety improvements by @0xLeif in #20
- Update LICENSE by @0xLeif in #19
- Refactor Cache locking mechanism to use NSRecursiveLock for improved thread safety and prevent deadlocks. Added comprehensive thread safety tests to validate the fix and ensure no new locking issues are introduced. by @0xLeif in #22
Full Changelog: 2.1.0...2.1.1
2.1.0
2.0.0
What's Changed
Added
AnyCacheabletype, enabling type erasure for anyCacheableobject.CacheInitializableprotocol, introducing an initializer forCacheableobjects.ComposableCachetype, allowing for the composition of multiple caches into a single cache.Loggingproperty wrapper, providing a convenient way to cache and retrieve loggers.Global.loggerscache, a required cache instance specifically designed for managing loggers.
Full Changelog: 1.6.0...2.0.0
1.6.0
Adds
-
RequiredKeysCache: Introduced a new cache type,
RequiredKeysCache, that ensures all specified keys are present in the cache at all times. This cache is useful when you have a defined set of keys that must always be present. -
Global Caches: Added three global cache instances to simplify usage:
cache: A global cache instance for generic caching needs.images: A global cache instance specifically designed for storing and retrieving images.dependencies: A global cache instance for storing and retrieving dependencies.
-
Property Wrappers: Added three new property wrappers for easy cache integration:
-
Cached: A property wrapper that automatically retrieves and caches the value from the associated cache. -
OptionallyCached: A property wrapper that retrieves the value from the associated cache if available, or falls back to the default value. -
Resolved: A property wrapper that resolves the value from the associated cache, throwing an error if the value is missing or cannot be resolved.
With these additions, the Cache library becomes even more versatile and convenient to use. Happy caching!
Test Coverage for Windows and Linux
-
Added tests for Windows platform to ensure compatibility and functionality on the Windows operating system.
-
Added tests for Linux platform to ensure compatibility and functionality on the Linux operating system.
What's Changed
- Leif/property wrappers by @0xLeif in #7
- Update README.md by @0xLeif in #9
- Add ubuntu and windows CI actions by @0xLeif in #8
Full Changelog: 1.5.0...1.6.0
1.5.0
LRUCache
LRUCache is a key-value store that uses the Least Recently Used (LRU) algorithm to evict items when the cache capacity is exceeded. This implementation is written in Swift and can be used in any iOS, macOS, or tvOS project. The cache contents are automatically loaded from the initial values dictionary when initialized.
The LRUCache is implemented as a subclass of the Cache class. You can use its capacity property to specify the maximum number of key-value pairs that the cache can hold. When the cache capacity is exceeded, the least recently used item is automatically evicted from the cache.
What's Changed
Full Changelog: 1.4.0...1.5.0
1.4.0
PersistableCache
The PersistableCache class is a cache that stores its contents persistently on disk using a JSON file. Use it to create a cache that persists its contents between application launches. The cache contents are automatically loaded from disk when initialized, and can be saved manually whenever required.
To use PersistableCache, make sure that the specified key type conforms to both RawRepresentable and Hashable protocols. The RawValue of Key must be a String type.
Here's an example of creating a cache, setting a value, and saving it to disk:
let cache = PersistableCache<String, Double>()
cache["pi"] = Double.pi
do {
try cache.save()
} catch {
print("Failed to save cache: \(error)")
}You can also load a previously saved cache from disk:
let cache = PersistableCache<String, Double>()
let pi = cache["pi"] // pi == Double.piRemember that the save() function may throw errors if the encoder fails to serialize the cache to JSON or the disk write operation fails. Make sure to handle the errors appropriately.
What's Changed
Full Changelog: 1.3.0...1.4.0
1.3.0
1.2.0
1.1.0
ExpiringCache
The ExpiringCache class is a cache that retains and returns objects for a specific duration set by the ExpirationDuration enumeration. Objects stored in the cache are automatically removed when their expiration duration has passed.
Usage
// Create an instance of the cache with a duration of 5 minutes
let cache = ExpiringCache<String, Int>(duration: .minutes(5))
// Store a value in the cache with a key
cache["Answer"] = 42
// Retrieve a value from the cache using its key
if let answer = cache["Answer"] {
print("The answer is \(answer)")
}Expiration Duration
The expiration duration of the cache can be set with the ExpirationDuration enumeration, which has three cases: seconds, minutes, and hours. Each case takes a single UInt argument to represent the duration of that time unit.
What's Changed
Full Changelog: 1.0.1...1.1.0