bchurchill / badi-cal

A javascript library for Badi calendar conversions.
https://bchurchill.github.io/badi-cal/
MIT License
11 stars 4 forks source link

Caching #11

Open bchurchill opened 7 years ago

bchurchill commented 7 years ago

Right now, every date is computed from scratch. One nicety is that we can compute provisional dates for future years based on the 10 July 2014 letter, but there are some downsides:

So, a totally reasonable thing to do would be to cache the computed values for all the years corresponding to the official dates provided by the Baha'i World Center. This offers two obvious advantages:

bchurchill commented 7 years ago

@brenmcnamara in your opinion, how should this be organized in the code base? My guess is that there are three things to be added:

  1. JSON data for the fixed dates of Naw-Ruz, the Twin Birthdays
  2. Code to generate the JSON data
  3. Code that decides whether to do a computation from scratch or use the cached value (i.e. the caching logic).

I feel like the first and third items are straightforward -- we could create a CacheData.js file with the JSON and Cache.js which has a class that accesses it (not exported). That leaves the second item, which is the code that generates the JSON file. This would be some code that isn't shipped as part of the BadiDate module, but would be run as needed (perhaps as part of an npm job). It's not really an "example" though. Do you have any suggestions?