Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed totalCostLimit from MemoryConfig #184

Merged
merged 1 commit into from
May 6, 2018
Merged

Removed totalCostLimit from MemoryConfig #184

merged 1 commit into from
May 6, 2018

Conversation

guoyingtao
Copy link
Contributor

For NSCache, I think the totalCostLimit doesn't work if you don't use setObject(_ obj: ObjectType, forKey key: KeyType, cost g: Int) and pass a cost of the object which you want to cache.

Also, I think it's not easy to get the cost of each object since they may be any type. So keeping this property may confuse user when they really try to set it.

I checked several image cache libraries based on NSCache and found they did passed the cost of the cached images because it's easy to get an image cost.

setObject function in MemoryStorage.swift

func setObject<T: Codable>(_ object: T, forKey key: String, expiry: Expiry? = nil) {
    let capsule = MemoryCapsule(value: object, expiry: .date(expiry?.date ?? config.expiry.date))
    cache.setObject(capsule, forKey: NSString(string: key))
    keys.insert(key)
}

@vadymmarkov
Copy link
Contributor

Makes sense to me. What do you think @onmyway133 ?

@onmyway133
Copy link
Contributor

👍

@vadymmarkov vadymmarkov merged commit cc82d70 into hyperoslo:master May 6, 2018
@guoyingtao guoyingtao deleted the RemoveCost branch May 7, 2018 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants