torchlight-api / torchlight-laravel

A Laravel client for Torchlight - the syntax highlighting API.
https://torchlight.dev
MIT License
113 stars 17 forks source link

💡 Add a cache command #21

Open PhiloNL opened 2 years ago

PhiloNL commented 2 years ago

I've been trying to build a cache command for Torchlight but haven't been able to wrap my head around how to approach this. If you use a post-processor, everything can be cached up front, similar to view:cache. This will eliminate on-demand requests.

Do you think this is possible with the current setup?

stevebauman commented 2 years ago

Hey Philo! I was able to tackle something similar with Statamic's static site generation plugin. Not sure if this helps you any: https://github.com/torchlight-api/torchlight-laravel/issues/22

The generated HTML is cached and the torchlight API is never hit when browsing the site (I use Netlify to host).

Though the only way I can think of to make this happen via a command would be to hit/crawl every page on the app, but since users may be using a database and have dynamic routing, this would be difficult to achieve. Maybe we could accomplish this with static routes only for its first iteration (i.e. omit any routes that contain parameters)?

We could possibly leverage the same flow/architecture as Statamics static site generation...