<div dir="ltr"><div><div>-----BEGIN PGP SIGNED MESSAGE-----</div><div>Hash: SHA1</div><div><br></div><div>Hello everyone,</div><div><br></div><div>I’m Luke, I spoke to some of you about Tor Explorer (<a href="https://github.com/lukechilds/tor-explorer">https://github.com/lukechilds/tor-explorer</a>) on IRC the other day.</div><div><br></div><div>I’ve separated the Onionoo bits from Tor Explorer out into a reusable Node.js module (<a href="https://github.com/lukechilds/onionoo-node-client">https://github.com/lukechilds/onionoo-node-client</a>). This will allow other people to easily include this module </div><div>in their Node.js projects and use the Onionoo API with minimal effort.</div><div><br></div><div>I’m just cleaning it up and making sure everything works properly before publishing v1. You can track progress here if you’re interested: <a href="https://github.com/lukechilds/onionoo-node-client/milestone/1">https://github.com/lukechilds/onionoo-node-client/milestone/1</a></div><div><br></div><div>I’m slightly confused about how to handle caching and was wondering if any Onionoo devs (or anyone else) could provide some guidance on a couple of questions I have.</div><div><br></div><div><br></div><div>1. Cache strategy</div><div><br></div><div>I’m currently just saving the responses in memory for however long the Cache-Control max-age header value says, after the max-age has expired a new request will be made. However I read this in the </div><div>docs:</div><div><br></div><div>> Clients should make use of the "Last-Modified" header of responses and include that timestamp in a "If-Modified-Since" header of subsequent requests.</div><div><br></div><div>This suggests I should be storing the responses indefinitely. After the max-age has expired I should do a new request with If-Modified-Since and if I get a 304, return my already cached value (and </div><div>possibly update the max-age in my cache?). Just double checking, is that correct?</div><div><br></div><div><br></div><div>2. How to calculate max-age</div><div><br></div><div>Regarding max-age, what is the correct value I should be using here? I was just using the Cache-Control max-age header value directly, however I noticed this often stays the same but the age </div><div>header increments. Possibly varnish caching the max-age header from Onionoo? So how should I reliably calculate the cache lifetime by the time I get the response?</div><div><br></div><div>I think this would offset the time Varnish has already been holding it for:</div><div><br></div><div>max-age - age = cache-lifetime-ms</div><div><br></div><div>but maybe this would be more accurate to compensate for network latency too:</div><div><br></div><div>date + max-age = valid-until-date</div><div>valid-until-date - now = cache-lifetime-ms</div><div><br></div><div><br></div><div>If anyone could offer some advice on these two issues that would be greatly appreciated</div><div><br></div><div>Cheers,</div><div>Luke</div><div><br></div><div>P.S I find GitHub issues to be quite efficient for discussing this sort of thing. If you have a GitHub account, feel free to post replies in the cache issue: </div><div><a href="https://github.com/lukechilds/onionoo-node-client/issues/2">https://github.com/lukechilds/onionoo-node-client/issues/2</a>. If you’d rather not use GitHub, no problem :)</div><div>-----BEGIN PGP SIGNATURE-----</div><div>Version: GnuPG v1</div><div><br></div><div>iQEcBAEBAgAGBQJYVkR7AAoJEJPWEqnWHCga+MQH/R2eH1OzvUgTKt8JV4Ve4hUX</div><div>hBLzLdgzRLSqpcYQXvAMHLT9Yo3fsCs1EtSEdrL6wYmcB0kK6Ql3CtKJA4ejy0kM</div><div>Aju9769/U+g5yta7sYNdkO6YYXxYKrhXpjFMslvI4s6z7Z8wtk1JRFHEG9h5gj/J</div><div>BjNgq/lqJFcNGE67chrf1BsD4FXUxXdM14uz1QEyt8M0GjvABUgMPSNHXIkN6bmX</div><div>U0DkT/hFSIRLNh6VzxVpS2goKt0X7E4eXQE2KDHKSsb7imvRU9y4mUA/DgiG7J1P</div><div>/K9gzTwF1EHKhGHE8UzthGv9isDpjuXYcGYxjP/DLoFnpB9nZkpUi3671l7oYwI=</div><div>=OEw1</div><div>-----END PGP SIGNATURE-----</div></div><div><br></div></div>