crazyfactory / tinka

Tinka is a dependency free fetch client, it's fetch on steroids
https://crazyfactory.github.io/tinka
MIT License
6 stars 4 forks source link

How to use cache middleware? #159

Closed cyberhck closed 6 years ago

cyberhck commented 6 years ago

Realizing we should have created proper docs for this repo.

What I want to know is when I add the cache middleware to tinka, how do I define which endpoints to cache and how long? After looking at tests, I think it is something like:

const tinka = new Client({baseUrl: "https://api.example.com"});
tinka.addMiddleware(new CacheMiddleware(new RedisAdapter()))
tinka.process({url: "/me", cache: {enable: true, maxAge: 10}});

Is that correct? @adhocore or we just configure at first and same ttl is applied for all?

if not, how do set it up? and how do we define life for each endpoints? Thanks in advance!

adhocore commented 6 years ago

aha been quite long. and most probably the code have been refactored by wolf since then.

that snippet looks correct (at least as pseudo code if not at all)

cyberhck commented 6 years ago

wolf only did minor changes, AFAIK, okay, I needed to know a little more caching because I was about to create an issue related to caching soon :slightly_smiling_face: thanks. /closing.