Coder Social home page Coder Social logo

Huge cache size about awesomecache HOT 5 CLOSED

MattesGroeger avatar MattesGroeger commented on May 22, 2024
Huge cache size

from awesomecache.

Comments (5)

aschuch avatar aschuch commented on May 22, 2024

Hm, this indeed sounds a bit strange. I've not experienced this.
AwesomeCache uses NSCoding and NSKeyedArchiver to persist objects under the hood.

Could you try and persist the picture using NSKeyedArchiver to try and see if the persisted object is of similar size?

from awesomecache.

MattesGroeger avatar MattesGroeger commented on May 22, 2024

I'll try that tomorrow.

When I inspected the cached binary I saw NSKeyedArchiver annotations already. Maybe this problem is also specific to JPEG files. Will investigate further tomorrow.

from awesomecache.

mbuchetics avatar mbuchetics commented on May 22, 2024

NSKeyedArchiver will persist the uncompressed UIImage and that's why you see the difference in size compared to the JPEG file. You would need to cache the data returned by UIImageJPEGRepresentation.

from awesomecache.

MattesGroeger avatar MattesGroeger commented on May 22, 2024

@mbuchetics Good point! Thanks a lot, that makes sense and I just changed our implementation accordingly:

Use NSData as cached type:

struct Images {
    static let cache = Cache<NSData>(name: "images")
}

Writing to cache:

if let data = UIImageJPEGRepresentation(processedImage, 0.6) {
    Images.cache.setObject(data,
        forKey: imageId,
        expires: cacheExpiry)
}

Reading from cache:

if let imageData = Images.cache[imageId] {
    return UIImage(data: imageData)
}

Now file sizes are under 1MB. Issue can be closed then. Keep up the good work!

from awesomecache.

aschuch avatar aschuch commented on May 22, 2024

@mbuchetics Thanks for the clarification.

@MattesGroeger Awesome, if you have further questions feel free to reopen. 🎇

from awesomecache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.