Giter Club home page Giter Club logo

Comments (5)

Exilz avatar Exilz commented on June 2, 2024

Hi,
have you tried using the setOptions method in order to update your cacheExpiration value from your header response ?

from apipeline.

jeyakumarsbe avatar jeyakumarsbe commented on June 2, 2024

Hi Exilz,

Thanks for your reply.
Yes, i tried setOptions method and i updated cacheExpiration, But this is set globally across all my API request. I have many API endpoints every endpoints having different expiry time.

Please see below my code. After calling the fetch method i can get this particular endpoint expiry time from Response "expirytime": 60000,
Now i want to set this time to my cache expiry time for this particular offername - offerone. (I have many offers name like offerone, offertwo, offerthree, ..... etc and each has different expiry time)

//Sample Code
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View } from 'react-native';
import OfflineFirstAPI from 'react-native-offline-api';

// Default API configuration
const API_OPTIONS = {
domains: { default: 'http://myapidomain.example.com'},
prefixes: { default: '' },
debugAPI: false,
printNetworkRequests: true
};

// Default Service configuration
const API_SERVICES = {
offers: {
path: 'offers/:offername'
}
};
const api = new OfflineFirstAPI(API_OPTIONS, API_SERVICES);

export default class Offers extends Component {

constructor(props) {
    super(props);
}

async componentDidMount() {
    const response = await api.fetch(
        'offers',
        {
            pathParameters: {offername:'offerone'},
        }
    );

    // Below is my API Response, Here i can get this endpoint expirytime in milliseconds. 
    // I want to set this expiry time to this particular API request

    // API Response JSON data
    /*
    {
        "success": true,
        "status": 200,
        "expirytime": 60000
        "data": {
            "id": 1,
            "name": "First Page",
            "description": "My Page description",
        }
    }
    */

}
render() {
    return (
        <View>
            <Text>First Offers Page</Text>
        </View>
    );
}

}

Thanks.

from apipeline.

Exilz avatar Exilz commented on June 2, 2024

Allright I get it now.

Can you declare a service for each one of your offers ? Or do you need to call them dynamically in your application ? Do you have like 3 different offernames that you know in advance ?

If you do, you could create a service for each one of them, and then use setServices to update the expiration value according to your header. I guess this is kinda hacky though...

If you don't, sadly I don't think there is a feature that lets you do that for now.

I'd be interested in hearing your ideas to resolve this particular problem by adding a feature in the API. This is probably not something a lot of people need to do, but if it's useful to you, someone else might need it in the future.

from apipeline.

jeyakumarsbe avatar jeyakumarsbe commented on June 2, 2024

Hi,

Sorry for the delay.

We are modified your code, We are taking expiration time from response.
In our API response header contain below Cache-Control header and its expiration time in max-age.
So we are setting this time to this particular endpoint. This is working fine.

Cache-Control: max-age=47394, must-revalidate, private

Basically the HTTP response header must contain the cache expiration time or data last modified time. Based on this time we set the cache expiration time on client side.

Please read this below API Cache Blog and get more idea about this.
http://www.apiacademy.co/how-to-http-caching-for-restful-hypermedia-apis/

Thanks,

from apipeline.

Exilz avatar Exilz commented on June 2, 2024

I'm not sure I understood what you meant by "We are modified your code"

Did you fork this plugin ? Or did my previous insight help you implement what you need ? Just so I know if I can close this issue.

from apipeline.

Related Issues (17)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.