# Caching M2M access token in Actions

**URL:** <https://community.auth0.com/t/caching-m2m-access-token-in-actions/100734>\
**Category:** Get Help\
**Tags:** actions-management-api, management-api\
**Created:** [February 17, 2023, 10:27am UTC](https://community.auth0.com/t/caching-m2m-access-token-in-actions/100734 "2023-02-17T10:27:47Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![rueben.tiow](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/rueben.tiow/32/11646_2.png) [@rueben.tiow](https://community.auth0.com/u/rueben.tiow)\
**Post date:** [February 18, 2023, 1:47am UTC](https://community.auth0.com/t/caching-m2m-access-token-in-actions/100734/4 "2023-02-18T01:47:54Z")

</div>

Hi @saiful1991,

Thank you for your patience.

After carefully going through our [Action Limitations](https://auth0.com/docs/customize/actions/limitations#:~:text=The%20cumulative%20size%20of%20cached%20keys%20and%20their%20values%20must%20not%20exceed%208192%20bytes) documentation, I noticed that it makes note that **the cumulative size of cached keys and their values must not exceed 8192 bytes.**

Given that, one way to make this work is to use a few cache (key, value) pairs to store the Management API Token.

Because Cache Keys are limited to 2048 bytes, we can make this work with 3 Cache items.

I have tested this myself and got it to work with the following:

```auto
    const management = new ManagementClient({
      domain: event.secrets.domain,
      clientId: event.secrets.clientID,
      clientSecret: event.secrets.clientSecret,
      audience: event.secrets.audience,
      tokenProvider: {
        enableCache: true,
        cacheTTLInSeconds: 86400
      }
    });

    //Get new access token and set it in cache
    const newToken = await management.getAccessToken();
    api.cache.set('first',newToken.slice(0,2048))
    api.cache.set('second', newToken.slice(2048,4096))
    api.cache.set('third', newToken.slice(4096))
    
    //Get the new Cached Token
    const getNewToken = api.cache.get('first').value + api.cache.get('second').value + api.cache.get('third').value
    console.log(getNewToken)

```

I hope this helps!

Please reach out again if you have any additional questions.

Thank you,  
Rueben

---

_[View the full topic](https://community.auth0.com/t/caching-m2m-access-token-in-actions/100734)._
