Closed zarov closed 6 years ago
Just a though, but a complementary strategy would be to limit the cache size by a size in MB rather than by a time expiration. I do not know how easy it is to implement though.
have you looked at https://www.npmjs.com/package/lru-cache ?
I agree, but the size of a javascript object in MB is rather complicated afaik. And the linked package is only having a size in term of number of object in it. I'd rather not add another dependency, but it is subject to discussion what is the best solution !
about the size, the max
cache size in lru-cache
is in not necessarily in MB but in the units your length
function provides to give an (possibly approximate) size of each object (and defaults to 1, to simply count objects).
That was just a proposition to be considered before we end up recoding it ;). I have no opinion on this maintainance / recoding tradeoff.
Closing since we merged #743
I wanted to talk more about caching and how we handle our resources in memory. I know I removed
CacheResource
in #687, but I'm having some regrets about it, I should have gone further than only replacing it by aMap
.Let's say I fetch a resource, and I want to parse it before using it: the perfect example is with
x-bil
textures for the elevation. It is logical to add it in the cache after the parsing. But if we are going to make the architecture more malleable, with providers/parsers/others separated, we have a problem here. How can we move the parser outside of this part if we still need to do some cache action after the parsing, knowing the cache is specific toOGCWebServiceHelper
here ?What we need is a global cache, for all classes in iTowns to use (but not in the public API !), as @autra suggested:
The last point could be taken into account when writing the first Cache, to ease the integration later also with other methods, like the
Cache
API.It could currently be used in
OGCWebServiceHelper
,TileProvider
,WFSProvider
and3dTilesProcessing
(removing the not so beautifulMath.random
mechanism).Anyone has a thought on this ?