Announcement

Collapse
No announcement yet.

How can I store and retrieve temporary data in the backend

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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?

  • #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.

    Comment


    • #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...
      X