hyperoslo / Cache

:package: Nothing but Cache.
Other
2.96k stars 335 forks source link

totalCostLimit on NSCache set but cost not set when adding objects. #292

Closed onato closed 5 months ago

onato commented 3 years ago

The totalCostLimit is correctly set, however, this has no affected on the MemoryStore because there is no cost provided when setting the objects. Hence the NSCache doesn't know what its current cost is and doesn't evict anything.

This line needs to have its cost parameter included. https://github.com/hyperoslo/Cache/blob/520b1afd229e25051878c65ce1e780628ea43b4d/Source/Shared/Storage/MemoryStorage.swift#L44

open class NSCache<KeyType, ObjectType> : NSObject where KeyType : AnyObject, ObjectType : AnyObject {
    …
    open func setObject(_ obj: ObjectType, forKey key: KeyType) // 0 cost

    open func setObject(_ obj: ObjectType, forKey key: KeyType, cost g: Int)
3lvis commented 5 months ago

Closing, reason outdated issue.