Untitled

 avatar
unknown
plain_text
a month ago
911 B
2
Indexable
import React, { useEffect, useState } from 'react';
import { View, Text, ActivityIndicator } from 'react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import axios from 'axios';

const AirtableAPI = () => {
  const [data, setData] = useState(null);
  const [loading, setLoading] = useState(true);

  const fetchDataFromAirtable = async () => {
    const cacheKey = 'airtable_data';
    const cacheDuration = 15 * 60 * 1000; // Cache for 15 minutes

    try {
      // Check cache
      const cachedData = await AsyncStorage.getItem(cacheKey);
      if (cachedData) {
        const parsedData = JSON.parse(cachedData);

        // Check if cache is still valid
        if (Date.now() - parsedData.timestamp < cacheDuration) {
          console.log('Fetching data from cache...');
          setData(parsedData.data);
          setLoading(false);
          return;
        }
     
Leave a Comment