How can I store and retrieve temporary data in the backend

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aldisa
    Junior Member
    • Jun 2023
    • 28

    How can I store and retrieve temporary data in the backend

    I am developing a backend custom module for integration with an external API that requires OAuth tokens. When I get an OAuth token, it is valid for one hour (3600 seconds). I want to store this token and its timestamp in the cache (write to cache). On next invocation, I want to reuse the token (read from cache) and only refresh it if is expired.

    How can I write to and read from cache in a custom module in the backend?
  • yuri
    Member
    • Mar 2014
    • 8452

    #2
    I'd recommend creating an entity. Give it some unique name like MyOauthAccount. Create fields 'accessToken', 'refreshToken', 'expiresAt'. Then create entry points to retrieve this data from in the frontend. Or use standard CRUD entry points, but it would require revising access control so that other users wouldn't be able to read. Maybe use an assignedUser field and read access level = own.
    If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

    Comment

    • aldisa
      Junior Member
      • Jun 2023
      • 28

      #3
      Thanks for your feedback, Yuri. There is a subfolder in the `data` folder called `tmp`. Can I use `file_put_contents()` and `file_read_contents()` to persist the token for the one hour? Would this approach conflict with any other type of usage within the framework?

      Comment

      Working...