developmentseed / titiler

Build your own Raster dynamic map tile services
https://developmentseed.org/titiler/
MIT License
766 stars 157 forks source link

Errors building Tiler with cache #605

Closed guillemc23 closed 1 year ago

guillemc23 commented 1 year ago

Hey! I'm trying to add cache to my Titiler instance, but I bumped into this line while following the docs.

https://github.com/developmentseed/titiler/blob/27b4972f21b245a4ca6bfcffae369a30e1171d0b/docs/src/examples/code/tiler_with_cache.md?plain=1#L169

In this line, it's trying to import MetadataParams (which is not used anywhere on the rest of the code, so I guess it should be removes) and TMSParams. Both of this names result in errors when importing as in:

ImportError: cannot import name 'MetadataParams' from 'titiler.core.dependencies' (/opt/bitnami/python/lib/python3.11/site-packages/titiler/core/dependencies.py)
ImportError: cannot import name 'TMSParams' from 'titiler.core.dependencies' (/opt/bitnami/python/lib/python3.11/site-packages/titiler/core/dependencies.py)

I am unable to find any reference to any of those dependencies in the official documentation. Were they moved/refactored/deprecated? How should I proceed to configuring Titiler with cache?

I'm running Titiler on a docker image from ghcr.io/developmentseed/titiler:latest.

Thank you!

vincentsarago commented 1 year ago

this example is old and should be updated, sorry about that

vincentsarago commented 1 year ago

fixed https://github.com/developmentseed/titiler/blob/c8c19b4809f1ca77c1db845a4e7c0332690189c2/docs/src/examples/code/tiler_with_cache.md

guillemc23 commented 1 year ago

Hello Vincent, thank you for your fast response. I will test this soon and check if everything is working as expected.

So far I have noticed we're still missing from typing import Optional but looks good 😉

guillemc23 commented 1 year ago

Hello again Vincent, the cache is working, but when an item is cached, it's returning a Starlette response object as in <starlette.responses.Response object at 0x7fc64bfd3850> that can't be understood by the browser nor Postman. media_type looks correct.

I think I'm missing something. Could you point me towards the right direction?

When loading a resource for the first time, works like a charm 😄

vincentsarago commented 1 year ago

@guillemc23 when I tried yesterday locally it seemed to work 🤷 I won't have time right now to check this 🙁

guillemc23 commented 1 year ago

@vincentsarago I wasn't able to make it work, I think there was something wrong with the deserializer. But I found another Python library which is newer and, according to the maintainers, faster than aiocache. It works with memory or redis and solves this issue mentioned in the docs:

Because aiocache.cached doesn't support non-async method we have to create a custom cached class

So it reduces the amount of code and it's much easier to set up 😄

If you're interested I can PR with the solution I found with this new library.

https://pypi.org/project/cashews/

vincentsarago commented 1 year ago

If you're interested I can PR with the solution I found with this new library.

🙏 yes that would be lovely

fabricebrito commented 4 months ago

@vincentsarago I confirm this is still the case. There's an issue in the serialization, the object is serialized as its string representation. So technically it's not a titiler issue be the recipe in the doc is broken.

@guillemc23 would you be available to share your approach with cashews?