tjtanjin / react-chatbotify

A modern React library for creating a flexible and extensible chatbot.
https://react-chatbotify.com
MIT License
148 stars 68 forks source link

Cache themes and retrieve from cache when available #94

Closed banani720 closed 3 weeks ago

banani720 commented 1 month ago

Description

This pull request caches the theme data with an expiry date of 30 days to local storage. If a theme exists it is returned and no call to the CDN to get the theme are made

Closes #85

What change does this PR introduce?

Please select the relevant option(s).

What is the proposed approach?

To resolve this issue I simply added cache setting/getting functions in order to check for a cached theme before going to the CDN. If there is no cached theme or it is expired, a call to the CDN is made and the result is then cached for future use. I chose 30 days as an arbitrary number but we can expand or reduce that as needed

Checklist:

banani720 commented 1 month ago

Hey @tjtanjin I'll get right on that, appreciate the feedback!

I had just one question regarding your third bullet, is the idea that the CSS styles text SHOULDN'T be cached?

banani720 commented 1 month ago

In the meantime, I've gone ahead and implemented a unique key for cached themes so that they don't overwrite and reworked getCachedTheme and setCachedTheme so that they handle undefined versions when setting cache keys. I've also gone ahead and redone the cache theme key to be rcb-theme in accordance with the naming standards I've seen elsewhere in the repo.

tjtanjin commented 1 month ago

Hey @banani720! Are you still working on this PR? If you require further clarifications feel free to ask 😊

tjtanjin commented 4 weeks ago

Any updates @banani720? 🥹

tjtanjin commented 3 weeks ago

Succeeded by #103