cherry-studio/packages/shared/data
MyPrototypeWhat 4f7a14b044 feat(tabs): implement LRU management and tab hibernation features
- Introduced `TabLRUManager` to manage tab hibernation based on usage patterns, enhancing memory efficiency.
- Added `isDormant` and `savedState` properties to the `Tab` interface for tracking tab states during hibernation.
- Updated `useTabs` hook to include methods for hibernating and waking tabs, along with pinning functionality to exempt tabs from LRU management.
- Enhanced `AppShell` to only render non-dormant tabs, improving user experience by focusing on active content.
- Implemented logging for tab state changes to facilitate debugging and monitoring of tab behavior.

These changes significantly improve the application's performance and user experience by optimizing tab management and memory usage.
2025-12-11 17:50:50 +08:00
..
api refactor: migrate tabs state from SQLite to localStorage cache 2025-11-26 11:51:36 +08:00
cache feat(tabs): implement LRU management and tab hibernation features 2025-12-11 17:50:50 +08:00
migration/v2 refactor: update migration types and imports for consistency 2025-11-20 22:42:43 +08:00
preference Merge 'main' into v2 2025-12-05 10:54:35 +08:00
README.md refactor: update data management documentation and structure 2025-09-16 17:30:02 +08:00

Cherry Studio Shared Data

This directory contains shared type definitions and schemas for the Cherry Studio data management systems. These files provide type safety and consistency across the entire application.

📁 Directory Structure

packages/shared/data/
├── api/                     # Data API type system
│   ├── index.ts            # Barrel exports for clean imports
│   ├── apiSchemas.ts       # API endpoint definitions and mappings
│   ├── apiTypes.ts         # Core request/response infrastructure types
│   ├── apiModels.ts        # Business entity types and DTOs
│   ├── apiPaths.ts         # API path definitions and utilities
│   └── errorCodes.ts       # Standardized error handling
├── cache/                   # Cache system type definitions
│   ├── cacheTypes.ts       # Core cache infrastructure types
│   ├── cacheSchemas.ts     # Cache key schemas and type mappings
│   └── cacheValueTypes.ts  # Cache value type definitions
├── preference/              # Preference system type definitions
│   ├── preferenceTypes.ts  # Core preference system types
│   └── preferenceSchemas.ts # Preference schemas and default values
└── README.md               # This file

🏗️ System Overview

This directory provides type definitions for three main data management systems:

API System (api/)

  • Purpose: Type-safe IPC communication between Main and Renderer processes
  • Features: RESTful patterns, error handling, business entity definitions
  • Usage: Ensures type safety for all data API operations

Cache System (cache/)

  • Purpose: Type definitions for three-layer caching architecture
  • Features: Memory/shared/persist cache schemas, TTL support, hook integration
  • Usage: Type-safe caching operations across the application

Preference System (preference/)

  • Purpose: User configuration and settings management
  • Features: 158 configuration items, default values, nested key support
  • Usage: Type-safe preference access and synchronization

📋 File Categories

Framework Infrastructure - These are TypeScript type definitions that:

  • Exist only at compile time
  • Provide type safety and IntelliSense support
  • Define contracts between application layers
  • Enable static analysis and error detection

📖 Usage Examples

API Types

// Import API types
import type { DataRequest, DataResponse, ApiSchemas } from '@shared/data/api'

Cache Types

// Import cache types
import type { UseCacheKey, UseSharedCacheKey } from '@shared/data/cache'

Preference Types

// Import preference types
import type { PreferenceKeyType, PreferenceDefaultScopeType } from '@shared/data/preference'

🔧 Development Guidelines

Adding Cache Types

  1. Add cache key to cache/cacheSchemas.ts
  2. Define value type in cache/cacheValueTypes.ts
  3. Update type mappings for type safety

Adding Preference Types

  1. Add preference key to preference/preferenceSchemas.ts
  2. Define default value and type
  3. Preference system automatically picks up new keys

Adding API Types

  1. Define business entities in api/apiModels.ts
  2. Add endpoint definitions to api/apiSchemas.ts
  3. Export types from api/index.ts

Best Practices

  • Use import type for type-only imports
  • Follow existing naming conventions
  • Document complex types with JSDoc
  • Maintain type safety across all imports

Main Process Services

  • src/main/data/CacheService.ts - Main process cache management
  • src/main/data/PreferenceService.ts - Preference management service
  • src/main/data/DataApiService.ts - Data API coordination service

Renderer Process Services

  • src/renderer/src/data/CacheService.ts - Renderer cache service
  • src/renderer/src/data/PreferenceService.ts - Renderer preference service
  • src/renderer/src/data/DataApiService.ts - Renderer API client