AdrianJSClark / aydsko-iracingdata

A .NET access library for querying the iRacing "Data" API.
MIT License
28 stars 8 forks source link

Cache the results of requests to iRacing. #165

Closed robgray closed 1 year ago

robgray commented 1 year ago

Given iRacing is rate limited and not super quick to call, it might be handy to provide a cache inside of IDataClient that keys on url.

In my use case I have a few people calling the service so calls like accessing member profiles and overall results, or things that might be called "often" by many people, like current championship standings could do with caching.

AdrianJSClark commented 1 year ago

Great idea.

There are some results that should be cached even longer term as well (tracks, lookups, etc).

robgray commented 1 year ago

For what it's worth it looks like iRacing caches calls on AWS S3, using a similar strategy (guid representing a call, I think) as I'm seeing calls to https://scorpio-assets.s3.amazonaws.com/production/data-server/cache/data-services/results/get/?AWSAccessKeyId= in my debug log. Maybe that's their CDN? Sensible defensive programming but it can't hurt to a cache closer to home.

AdrianJSClark commented 1 year ago

Yup. Almost every method you call on my client makes 2 HTTP requests. First to call the Data API endpoint, second to convert the link that is returned into JSON that can be processed.

That's what the DataResponse<TData>.DataExpires property is all about. That would be the basis for expiring the cache items.

AdrianJSClark commented 1 year ago

Didn't mean to close it - this is only partially implemented.