Comments (13)
Hello @kiwo12345, thank you for very good questions.
1) Does this lib cache images by default?
The answer is not simply yes or no, it is more subtle. By default, moa uses the caching strategy from the HTTP response. If caching is configured on your server then, yes, moa will cache the images accordingly.
// Default setting
Moa.settings.cache.requestCachePolicy = .useProtocolCachePolicy
2) Must I change some settings in Moa?
If you want to always cache images and ignore their HTTP caching policy, please use the returnCacheDataElseLoad
setting. This can be used if one does not have control over the server caching settings.
Moa.settings.cache.requestCachePolicy = .returnCacheDataElseLoad
3) This might not belong here but does Moa clear the cache once it get full?
Moa uses URLSession
caching built into the OS. If I remember correctly, the oldest images are automatically removed from the cache once it gets full to make some room for the new ones.
4) I am used to Kingfisher where most of the stuff is configured out of the box, cache clear, cache time etc
This is wonderful, Kingfisher is one of the libraries I recommend as a good alternative to moa.
5) Caching manual
If you need more information about caching in moa, please refer to the caching manual.
Let me know how it goes.
from moa.
@evgenyneu thanks for your answer! And sorry, I had two tabs open and thought I posted my question in the Auk lib.
I will then use Moa.settings.cache.requestCachePolicy = .returnCacheDataElseLoad
in Auk :)
from moa.
No worries, I will leave this issue open. I think it is a very good question and it will be useful to others.
from moa.
@evgenyneu +1 for this tip you left in another issue: Moa.settings.cache.diskPath = "MyAppSharedCache"
this way I can make the two libs use the same cache directory :)
from moa.
I am glad it was helpful. Let me know if you see any issue, so we can make the library better.
from moa.
do I set all this in viewDidLoad? @kiwo12345 @evgenyneu
from moa.
@yarodevuci, thanks for the question. The caching settings can be changed at any point in your program, including viewDidLoad
. These settings will apply to all subsequent image loads.
from moa.
@evgenyneu Thanks for quick response
@evgenyneu your library does not work for me. Unfortunate
My downloads are getting cancelled all the time. What should I do?
Here is my code:
let moa = Moa()
moa.onSuccess = { image in
// image is loaded
mediaMessage.image = image
DispatchQueue.main.async(execute: {
self.tableView.reloadData()
})
return image
}
moa.url = sendedImageURL
Console output:
[moa] 2017-05-06 07:15:51.210 GET https://**
[moa] 2017-05-06 07:15:51.212 Cancelled https://**
Image never gets loaded..:(
from moa.
@yarodevuci, the image download might be cancelled if another download is started. This can happen, for example, if you execute moa.url = sendedImageURL
twice for the same Moa
object. I would suggest placing a breakpoint at this line and see when it is called.
from moa.
Just curious, is it possible for you to use the moa
property of the image?
mediaMessage.image.moa.url = "https://..."
If that's possible, that would make the program much simpler. :)
from moa.
@evgenyneu
Well, funny thing that I even tried put this in viewdidload
let moa = Moa()
moa.onSuccess = { image in
return image
}
moa.url = "https://..."
and same result.
from moa.
Oh, I probably know what it is :). The Moa
object that you initialized in the function gets destroyed when the function exits. That cancels the download. I would suggest making let moa = Moa()
an instance variable in the class instead.
from moa.
@evgenyneu yep, that did the trick! Thanks
from moa.
Related Issues (19)
- Some error after update to last version 5.0.0 HOT 5
- ** BUILD FAILED ** with Carthage, Xcode 7.3.1 HOT 3
- tvOS and LCR images HOT 3
- Image never loads
- determining if image was loaded from cache HOT 5
- Image flicker when table view reload called HOT 3
- moa.MoaError.notAnImageContentTypeInResponseHttpHeader HOT 8
- cannot shown image from links HOT 5
- Unable to have simultaneous downloads/load from cache HOT 2
- Adding Custom Headers to download request (Bearer {{access_token}}) for example HOT 1
- Request to bump iOS deployment target for Xcode 14.X build HOT 1
- Failure when downloading .gif in 3.0 HOT 3
- Placeholder image in moa? HOT 2
- What cache policy is the best for this situation ? HOT 2
- Animate Image after downloading HOT 1
- I still use the Swift2.2 HOT 1
- [QUESTION] Manually invalidating cache HOT 1
- etag caching not working as expected HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from moa.