@@ -8,23 +8,30 @@ import { buildKeyGenerator, setupCache } from 'axios-cache-interceptor';
88
99import type { Account , Link , Token } from '../../types' ;
1010import { decryptValue } from '../comms' ;
11- import { rendererLogError } from '../logger' ;
11+ import { rendererLogError } from '../logger' ;
1212import { getNextURLFromLinkHeader } from './utils' ;
1313
1414type AxiosRequestConfigWithAccount = AxiosRequestConfig & { account : Account } ;
1515
16+ // const MUTATION_HTTP_METHODS: Set<Method> = new Set(['PATCH', 'PUT', 'DELETE']);
17+
1618const instance = Axios . create ( ) ;
1719const axios = setupCache ( instance , {
1820 location : 'client' ,
1921
22+ // Respect ETags and cache headers from GitHub API
23+ interpretHeader : true ,
24+
25+ // Set a reasonable TTL to ensure cache freshness (60 seconds)
26+ // This ensures external changes (GitHub web/mobile) are picked up periodically
27+ // ttl: 1000 * 60, // 60 seconds
28+
2029 cachePredicate : {
21- ignoreUrls : [
22- '/login/oauth/access_token' ,
23- // '/notifications',
24- // '/api/v3/notifications',
25- ] ,
30+ ignoreUrls : [ '/login/oauth/access_token' ] ,
2631 } ,
2732
33+ methods : [ 'get' ] ,
34+
2835 generateKey : buildKeyGenerator ( ( request : AxiosRequestConfigWithAccount ) => {
2936 return {
3037 method : request . method ,
@@ -34,6 +41,24 @@ const axios = setupCache(instance, {
3441 } ) ,
3542} ) ;
3643
44+ // Invalidate cache on mutating requests (PATCH, PUT, DELETE)
45+ // Only clears cache entries for the same account that made the mutation
46+ // axios.interceptors.response.use(
47+ // async (response) => {
48+ // const method = response.config.method?.toUpperCase() as Method;
49+ // const config = response.config as AxiosRequestConfigWithAccount;
50+
51+ // if (MUTATION_HTTP_METHODS.has(method) && config.account) {
52+ // await clearFullApiCache();
53+ // }
54+ // return response;
55+ // },
56+ // (error: Error) => {
57+ // // Pass through errors without clearing cache
58+ // return Promise.reject(error);
59+ // },
60+ // );
61+
3762/**
3863 * Perform an unauthenticated API request
3964 *
@@ -139,10 +164,10 @@ async function getHeaders(token?: Token) {
139164 return headers ;
140165}
141166
142- export async function clearApiCache ( ) : Promise < void > {
143- try {
144- axios . storage . clear ( ) ;
145- } catch ( err ) {
146- rendererLogError ( 'clearApiCache ' , 'Failed to clear API cache' , err ) ;
147- }
167+ export async function clearFullApiCache ( ) : Promise < void > {
168+ // try {
169+ // axios.storage.clear();
170+ // } catch (err) {
171+ // rendererLogError('clearFullApiCache ', 'Failed to clear API cache', err);
172+ // }
148173}
0 commit comments