feat(profile): add chat settings and language options to profile settings
- Introduced hrefProfileChatSettings() for navigation to chat settings. - Updated SettingsScreen to include new settings items for chat settings, language selection, data storage, terms, and privacy policy. - Enhanced user experience by providing alerts for language and data storage options. This update improves the profile settings interface by adding more customization options for users.
This commit is contained in:
42
src/stores/utils/cache.ts
Normal file
42
src/stores/utils/cache.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 缓存工具函数
|
||||
* 提取自 baseManager.ts,用于 Zustand store 的 TTL 缓存管理
|
||||
*/
|
||||
|
||||
/** 缓存条目结构 */
|
||||
export interface CacheEntry<T> {
|
||||
data: T;
|
||||
timestamp: number;
|
||||
ttl: number;
|
||||
}
|
||||
|
||||
/** 创建缓存条目 */
|
||||
export function createCacheEntry<T>(data: T, ttl: number): CacheEntry<T> {
|
||||
return { data, timestamp: Date.now(), ttl };
|
||||
}
|
||||
|
||||
/** 检查缓存是否过期 */
|
||||
export function isCacheExpired(entry: CacheEntry<any>): boolean {
|
||||
return Date.now() - entry.timestamp > entry.ttl;
|
||||
}
|
||||
|
||||
/** 检查缓存是否有效(存在且未过期) */
|
||||
export function isCacheValid<T>(entry: CacheEntry<T> | undefined | null): boolean {
|
||||
if (!entry) return false;
|
||||
return !isCacheExpired(entry);
|
||||
}
|
||||
|
||||
/** 获取缓存的剩余有效时间(毫秒) */
|
||||
export function getCacheRemainingTTL(entry: CacheEntry<any>): number {
|
||||
const elapsed = Date.now() - entry.timestamp;
|
||||
return Math.max(0, entry.ttl - elapsed);
|
||||
}
|
||||
|
||||
/** 默认 TTL 常量 */
|
||||
export const DEFAULT_TTL = {
|
||||
USER: 5 * 60 * 1000, // 5 分钟
|
||||
POST_LIST: 30 * 1000, // 30 秒
|
||||
POST_DETAIL: 60 * 1000, // 1 分钟
|
||||
GROUP: 60 * 1000, // 1 分钟
|
||||
GROUP_MEMBERS: 120 * 1000, // 2 分钟
|
||||
};
|
||||
Reference in New Issue
Block a user