capacitor-cors-bypass-enhanced
Version:
Enhanced Capacitor plugin for CORS bypass with HTTP/2, HTTP/3, gRPC, GraphQL, file operations, and advanced networking features. Modular TypeScript definitions for better maintainability.
119 lines • 2.98 kB
TypeScript
/**
* Cache Interceptor
* 缓存拦截器实现
*/
import type { Interceptor, HttpRequestOptions, HttpResponse, HttpError } from '../definitions';
import type { CacheInterceptorOptions, OfflineOptions } from '../types/cache';
import { type CacheManager } from './cache';
/**
* 缓存拦截器类
*/
export declare class CacheInterceptor implements Interceptor {
private cacheManager;
private options;
private offlineOptions?;
constructor(options?: CacheInterceptorOptions, offlineOptions?: OfflineOptions);
/**
* 请求拦截器
*/
onRequest(config: HttpRequestOptions): Promise<HttpRequestOptions>;
/**
* 响应拦截器
*/
onResponse(response: HttpResponse): Promise<HttpResponse>;
/**
* 错误拦截器
*/
onError(error: HttpError): Promise<void | HttpResponse>;
/**
* 生成缓存键
*/
private generateCacheKey;
/**
* 检查是否应该排除此请求
*/
private shouldExclude;
/**
* 将缓存条目转换为响应
*/
private entryToResponse;
/**
* 计算数据大小
*/
private calculateSize;
/**
* 压缩数据
*/
private compressData;
/**
* 解压数据
*/
private decompressData;
/**
* 后台重新验证
*/
private backgroundRevalidate;
/**
* 检查是否离线
*/
private checkOffline;
/**
* 处理离线请求
*/
private handleOfflineRequest;
/**
* 处理离线错误
*/
private handleOfflineError;
/**
* 获取缓存管理器
*/
getCacheManager(): CacheManager;
/**
* 清空缓存
*/
clearCache(): Promise<void>;
/**
* 获取缓存统计
*/
getStats(): Promise<import("../definitions").CacheStats>;
/**
* 清理过期缓存
*/
cleanup(): Promise<number>;
}
/**
* 创建缓存拦截器的便捷函数
*/
export declare function createCacheInterceptor(options?: CacheInterceptorOptions, offlineOptions?: OfflineOptions): CacheInterceptor;
/**
* 预设的缓存策略
*/
export declare const CacheStrategies: {
/**
* 网络优先策略
* 优先从网络获取,失败时使用缓存
*/
networkFirst: (maxAge?: number) => CacheInterceptorOptions;
/**
* 缓存优先策略
* 优先使用缓存,缓存不存在时从网络获取
*/
cacheFirst: (maxAge?: number) => CacheInterceptorOptions;
/**
* 仅网络策略
* 总是从网络获取,不使用缓存
*/
networkOnly: () => CacheInterceptorOptions;
/**
* 仅缓存策略
* 只使用缓存,不发起网络请求
*/
cacheOnly: (maxAge?: number) => CacheInterceptorOptions;
/**
* 陈旧重新验证策略
* 立即返回缓存,同时在后台更新
*/
staleWhileRevalidate: (maxAge?: number) => CacheInterceptorOptions;
};
//# sourceMappingURL=cache-interceptor.d.ts.map