CAVEconnectome / CAVEclient

This is the python client for accessing REST APIs within the Connectome Annotation Versioning Engine.
https://caveconnectome.github.io/CAVEclient/
MIT License
21 stars 11 forks source link

Set info cache from dict #75

Closed ceesem closed 2 years ago

ceesem commented 2 years ago

Small fix to allow info_cache to be passed to the caveclient.

The idea here is that if one is working in a programmatic situation where many cave clients are being initialized all the time, the info cache could itself be cached (e.g. an LRU cache hashed by data stack and server name with an expiration time of an hour), avoiding an extra lookup roundtrip and an extra hit on the info service to get the same dict upon each caveclient initialization.

ceesem commented 2 years ago

Because I know that having to roll your own solution every single time is a good way to make something never used, I added a small function tools.caching.CachedClient that generates a client using the type of cache I just mentioned.

ceesem commented 2 years ago

As a bonus, this saves ~0.6 seconds on subsequent initializations!