c12i / mpesa-rust

A MPESA API sdk in Rust
https://c12i.github.io/mpesa-rust/mpesa/index.html
MIT License
43 stars 14 forks source link

Cache `access_token` and re-use for subsequent request #68

Closed itsyaasir closed 9 months ago

itsyaasir commented 1 year ago

Currently, we are fetching new key for any request we make, while I don't think there's any problems with it, we can make it more efficient and save on more calls.

My proposal is we can cache the access token which is valid for one hour, and reuse that for the subsequent calls, until the key expires (which is normally one hour). I think this should be pretty easy to make it.

What do you think @collinsmuriuki ?

c12i commented 1 year ago

Thanks for this suggestion, its something that I have considered doing and led me down the path of creating a ttl cache macro as a side project. We could definitely use with caching for the access token. Could experiement my custom lib (https://github.com/collinsmuriuki/simple_cache) here or use an existing/ well tested solution.

Interested in taking this up?

dxphilo commented 1 year ago

@collinsmuriuki I can pick this up

c12i commented 1 year ago

Sure thing @dxphilo, go for it