question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Caching requested data

See original GitHub issue

Hello! And thanks for creating and maintaining this great lib!

I’ve read the README and checked the issues, but couldn’t find a way to “cache” the data to avoid requesting it again. For example, my view requests the data. Then I route to another view, and later I come back. The data will be requested again.

One option would be to check in the component, before requesting the data, to see if the data is already there. But instead of each component doing the check, it would be better if the store did it. Maybe the beforeRequest can be used for this?

And sometimes the same endpoint can return data about different elements. I try to store them in an object, like the code bellow. But then, how can I get the element “id” in the onSuccess, so I can store it in the object?

Component

  mounted () {
    this.getYearInfo({ params: { year: this.$route.params.year } })
  },
  computed: mapState({
    yearsInfo: state => state.yearInfo
  }),
  methods: {
    ...mapActions([
      'getYearInfo'
    ])
  }

Store

const year = new Vapi({
  baseURL: baseUrls.year,
  state: {
    yearInfo: {},
  }
}).get({
  action: 'getYearInfo',
  property: 'yearInfo',
  path: ({ year }) => `/info/${year}`,
  onSuccess: (state, payload, axios) => {
    // How do I get the year here?
    state.yearInfo[year] = payload.data
  }
}).getStore()

I saw something about axios being able to cache GET requests. Would it be a better solution for this issue?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
andresmrmcommented, Sep 7, 2018

Wow! Thank you! =D

0reactions
christianmalekcommented, Sep 7, 2018

I’ve added the {params, data} as additional parameter in the onSuccess and onError functions so you can access them now. Therefore please update to v2.10.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is Caching and How it Works | AWS
A cache is a high-speed data storage layer which stores a subset of data, typically transient in nature, so that future requests for...
Read more >
Caching of GET requests - IBM
Caching is used for a request if the entity tag (ETag) value of the request matches the value of the previous request. Caching...
Read more >
Request.cache - Web APIs | MDN
The cache read-only property of the Request interface contains the cache mode of the request. It controls how the request will interact with ......
Read more >
What is Caching and How It Works
A cache is a software or hardware component aimed at storing data so that future requests for the same data can be served...
Read more >
Caching strategies to speed up your API - LogRocket Blog
This technique is used in every NoSQL and SQL database internally. First, the data will be written in memory. The database acknowledges the ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found