{"id":29533562,"url":"https://github.com/Taiizor/tauri-plugin-cache","last_synced_at":"2025-07-17T00:04:36.044Z","repository":{"id":294561877,"uuid":"985074884","full_name":"Taiizor/tauri-plugin-cache","owner":"Taiizor","description":"🚀 Supercharge your Tauri app with intelligent disk \u0026 memory caching. Features TTL, compression, auto-cleanup, and cross-platform support for optimized performance.","archived":false,"fork":false,"pushed_at":"2025-07-15T03:27:31.000Z","size":726,"stargazers_count":9,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-07-15T08:42:04.537Z","etag":null,"topics":["auto-cleanup","cache","cache-storage","cleanup","compression","cross-platform","expiration","javascript","memory","optimization","performance","rust","statistics","storage","tauri","tauri-plugin","tauri-v2","ttl","typescript"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/tauri-plugin-cache","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Taiizor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-05-17T02:51:28.000Z","updated_at":"2025-07-15T03:27:34.000Z","dependencies_parsed_at":"2025-07-15T05:11:12.682Z","dependency_job_id":"87227b2c-03d0-44dc-9f5b-409a59406f8c","html_url":"https://github.com/Taiizor/tauri-plugin-cache","commit_stats":null,"previous_names":["taiizor/tauri-plugin-cache"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/Taiizor/tauri-plugin-cache","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taiizor%2Ftauri-plugin-cache","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taiizor%2Ftauri-plugin-cache/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taiizor%2Ftauri-plugin-cache/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taiizor%2Ftauri-plugin-cache/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Taiizor","download_url":"https://codeload.github.com/Taiizor/tauri-plugin-cache/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Taiizor%2Ftauri-plugin-cache/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265445302,"owners_count":23766445,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auto-cleanup","cache","cache-storage","cleanup","compression","cross-platform","expiration","javascript","memory","optimization","performance","rust","statistics","storage","tauri","tauri-plugin","tauri-v2","ttl","typescript"],"created_at":"2025-07-17T00:01:51.071Z","updated_at":"2025-07-17T00:04:36.038Z","avatar_url":"https://github.com/Taiizor.png","language":"Rust","funding_links":[],"categories":["Development"],"sub_categories":["Plugins"],"readme":"# Tauri Plugin Cache\n\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/Taiizor/tauri-plugin-cache/blob/develop/LICENSE)\n\nAn advanced, versatile, and performance-focused disk caching solution for Tauri applications. This plugin features powerful compression support, memory caching layer, configurable time-to-live (TTL) management, automatic cleanup, and cross-platform compatibility. It enables persistent storage of data on disk for fast access and optimizes application performance through intelligent caching strategies. Working seamlessly on both desktop and mobile platforms, it significantly enhances the data management capabilities of your Tauri applications.\n\n## Features\n\n- **Type Safety**: Full TypeScript typings\n- **Cache Statistics**: Monitor cache usage\n- **Cross-Platform**: Works on desktop and mobile\n- **Optional TTL**: Set expiration times for cache items\n- **Disk-based Cache**: Persistent data storage and retrieval\n- **Data Compression**: Enable compression for large data items\n- **Customizable Storage**: Configure where cache files are stored\n- **Automatic Cleanup**: Background task to remove expired items\n- **Smart Compression**: Configurable compression levels and thresholds\n- **Configurable Cache Location**: Customize where cache files are stored\n- **Memory Caching**: In-memory caching layer for improved performance\n- **Performance Optimized**: Buffered I/O and chunked processing for large datasets\n- **Multiple Compression Methods**: Choose between Zlib (fast) and LZMA2 (high ratio)\n\n## Installation\n\n### Using Tauri CLI (Recommended)\n\nThe easiest way to install this plugin is using the Tauri CLI, which automatically adds both Rust and JavaScript dependencies to your project:\n\n```bash\n# Using npm\nnpm run tauri add cache\n\n# Using pnpm\npnpm tauri add cache\n\n# Using yarn\nyarn tauri add cache\n```\n\nThis will:\n- Add the `tauri-plugin-cache` crate to your `Cargo.toml`\n- Install the `tauri-plugin-cache-api` npm package\n- Set up the necessary configurations\n\n### Manual Installation\n\nIf you prefer to manually install the plugin, you can follow these steps:\n\n#### Rust Dependencies\n\nAdd this plugin to your project using one of these methods:\n\n```bash\n# Using cargo add\ncargo add tauri-plugin-cache\n```\n\nOr manually add to your `Cargo.toml` file:\n\n```toml\n[dependencies]\ntauri = { version = \"2.5.1\" }\ntauri-plugin-cache = \"0.1.5\"\n```\n\n#### JavaScript/TypeScript API\n\nAdd the plugin API package to your project:\n\n```bash\npnpm install tauri-plugin-cache-api\n# or\nnpm install tauri-plugin-cache-api\n# or\nyarn add tauri-plugin-cache-api\n```\n\n## Setup\n\nRegister the plugin in your `tauri.conf.json` and/or in your Rust code:\n\n```rust\n// Basic setup with default configuration\nfn main() {\n    tauri::Builder::default()\n        .plugin(tauri_plugin_cache::init())\n        .run(tauri::generate_context!())\n        .expect(\"error while running tauri application\");\n}\n\n// Or with custom configuration\nfn main() {\n    let cache_config = tauri_plugin_cache::CacheConfig {\n        cache_dir: Some(\"my_app_cache\".into()),                                  // Custom subdirectory within app's cache directory\n        cache_file_name: Some(\"cache_data.json\".into()),                         // Custom cache file name\n        cleanup_interval: Some(120),                                             // Clean expired items every 120 seconds\n        default_compression: Some(true),                                         // Enable compression by default\n        compression_level: Some(7),                                              // Higher compression level (0-9, where 9 is max)\n        compression_threshold: Some(4096),                                       // Only compress items larger than 4KB\n        compression_method: Some(tauri_plugin_cache::CompressionMethod::Lzma2),  // Default compression algorithm\n    };\n    \n    tauri::Builder::default()\n        .plugin(tauri_plugin_cache::init_with_config(cache_config))\n        .run(tauri::generate_context!())\n        .expect(\"error while running tauri application\");\n}\n```\n\n\u003e **Note:** When specifying `cache_dir`, it's recommended to use relative paths instead of absolute paths. The plugin will create this directory inside the app's default cache directory location. If an absolute path is provided, only the last component of the path will be used as a subdirectory name within the app's cache directory.\n\n## Permissions\n\nBy default all plugin commands are blocked and cannot be accessed. You must modify the permissions in your `capabilities` configuration to enable these.\n\nSee the [Capabilities Overview](https://v2.tauri.app/security/capabilities) for more information.\n\n### Example Capability Configuration\n\n```json\n{\n  \"$schema\": \"../gen/schemas/desktop-schema.json\",\n  \"identifier\": \"cache-access\",\n  \"description\": \"Capability to access the cache functionality\",\n  \"windows\": [\"main\"],\n  \"permissions\": [\n    \"cache:default\"\n  ]\n}\n```\n\nThen enable this capability in your `tauri.conf.json`:\n\n```json\n{\n  \"app\": {\n    \"security\": {\n      \"capabilities\": [\"cache-access\"]\n    }\n  }\n}\n```\n\n### Default Permission\n\nThe `cache:default` permission set configures which cache features are exposed by default.\n\n#### Granted Permissions\nThis enables all cache operations including setting, getting, and removing cached data.\n\n#### This default permission set includes the following:\n- `cache:allow-set`\n- `cache:allow-get`\n- `cache:allow-has`\n- `cache:allow-remove`\n- `cache:allow-clear`\n- `cache:allow-stats`\n\n### Permission Table\n\n| Permission | Description |\n|------------|-------------|\n| cache:allow-set | Allows setting data in the cache |\n| cache:deny-set | Denies setting data in the cache |\n| cache:allow-get | Allows retrieving data from the cache |\n| cache:deny-get | Denies retrieving data from the cache |\n| cache:allow-has | Allows checking if data exists in the cache |\n| cache:deny-has | Denies checking if data exists in the cache |\n| cache:allow-remove | Allows removing data from the cache |\n| cache:deny-remove | Denies removing data from the cache |\n| cache:allow-clear | Allows clearing all data from the cache |\n| cache:deny-clear | Denies clearing all data from the cache |\n| cache:allow-stats | Allows retrieving statistics about the cache |\n| cache:deny-stats | Denies retrieving statistics about the cache |\n\n## Usage\n\n### JavaScript/TypeScript Example\n\n```typescript\nimport { set, get, has, remove, clear, stats } from 'tauri-plugin-cache-api';\n\n// Store a value with TTL\nawait set('user', { name: 'John', age: 30 }, { ttl: 60 }); // Expires in 60 seconds\n\n// Store a large value with compression\nawait set('largeData', largeObject, { compress: true });\n\n// Store a value with both TTL and compression\nawait set('temporaryData', data, { ttl: 300, compress: true });\n\n// Retrieve a value (returns null if not found or expired)\nconst user = await get\u003c{ name: string, age: number }\u003e('user');\nif (user) {\n  console.log(user.name); // \"John\"\n}\n\n// Check if a key exists and is not expired\nconst exists = await has('user');\nif (exists) {\n  console.log('User exists in cache');\n}\n\n// Remove a value\nawait remove('user');\n\n// Get cache statistics\nconst statistics = await stats();\nconsole.log(`Cache has ${statistics.totalSize} items (${statistics.activeSize} active)`);\n\n// Clear all values\nawait clear();\n```\n\n### Rust Example\n\n```rust\nuse tauri::Manager;\nuse tauri_plugin_cache::CacheExt;\n\n// In a command or elsewhere with access to the app handle\n#[tauri::command]\nasync fn demo_cache(app_handle: tauri::AppHandle) -\u003e Result\u003cString, String\u003e {\n    // Access the cache\n    let cache = app_handle.cache();\n    \n    // Store a value with TTL\n    let options = Some(tauri_plugin_cache::SetItemOptions { \n        ttl: Some(60),\n        compress: None, // Use default compression setting\n        compression_method: None, // Use default compression method\n    });\n    cache.set(\"key\".to_string(), \"value\", options).map_err(|e| e.to_string())?;\n    \n    // Store a value with compression\n    let compress_options = Some(tauri_plugin_cache::SetItemOptions {\n        ttl: None,\n        compress: Some(true), // Enable compression\n        compression_method: Some(tauri_plugin_cache::CompressionMethod::Lzma2), // Use LZMA2\n    });\n    cache.set(\"large_key\".to_string(), large_value, compress_options).map_err(|e| e.to_string())?;\n    \n    // Get a value\n    let value: Option\u003cString\u003e = cache.get(\"key\")\n        .map_err(|e| e.to_string())?\n        .and_then(|v| serde_json::from_value(v).ok());\n        \n    // Check if a key exists\n    let exists = cache.has(\"key\").map_err(|e| e.to_string())?.value;\n    \n    // Remove a value\n    cache.remove(\"key\").map_err(|e| e.to_string())?;\n    \n    // Clear all values\n    cache.clear().map_err(|e| e.to_string())?;\n    \n    Ok(\"Cache operations completed\".to_string())\n}\n```\n\n## API\n\n### JavaScript/TypeScript API\n\n#### `set(key: string, value: any, options?: SetItemOptions): Promise\u003cvoid\u003e`\n\nSets an item in the cache with optional TTL and compression.\n\n- `key`: The key to store the value under\n- `value`: The value to store (will be JSON serialized)\n- `options`: Optional settings\n  - `ttl`: Time-to-live in seconds (item will be deleted after this time)\n  - `compress`: Whether to compress the data before storing\n  - `compressionMethod`: Compression method to use (CompressionMethod.Zlib or CompressionMethod.Lzma2)\n\n#### `get\u003cT = any\u003e(key: string): Promise\u003cT | null\u003e`\n\nGets an item from the cache.\n\n- `key`: The key to retrieve\n- Returns: The stored value (type T) or null if not found or expired\n\n#### `has(key: string): Promise\u003cboolean\u003e`\n\nChecks if an item exists in the cache and is not expired.\n\n- `key`: The key to check\n- Returns: True if the item exists and is not expired\n\n#### `remove(key: string): Promise\u003cvoid\u003e`\n\nRemoves an item from the cache.\n\n- `key`: The key to remove\n\n#### `clear(): Promise\u003cvoid\u003e`\n\nClears all items from the cache.\n\n#### `stats(): Promise\u003cCacheStats\u003e`\n\nGets cache statistics.\n\n- Returns: An object with statistics about the cache\n  - `totalSize`: Total number of items in the cache\n  - `activeSize`: Number of active (non-expired) items\n\n## Compression\n\nThis plugin supports data compression to reduce the disk space used by cache items. You can enable compression for individual items or set it as the default for all cache items.\n\n### Compression Methods\n\nThe plugin supports multiple compression methods to optimize storage based on your specific needs:\n\n- **Zlib**: Default method, provides a good balance between compression ratio and speed\n- **LZMA2**: Better compression ratio (especially for base64 encoded data), but slower compression speed\n\n### Benefits of Compression\n\n- **Reduced Disk Usage**: Compresses data to save disk space\n- **Improved I/O Performance**: Smaller data sizes mean faster read/write operations\n- **Network Efficiency**: If you sync cache data over a network, compressed data reduces bandwidth usage\n\n### Configuration Options\n\nYou can configure the default compression behavior when initializing the plugin:\n\n```rust\nlet cache_config = tauri_plugin_cache::CacheConfig {\n    default_compression: Some(true), // Enable compression by default\n    compression_level: Some(7),      // Higher compression level (0-9)\n    compression_threshold: Some(4096), // Only compress items larger than 4KB\n    compression_method: Some(tauri_plugin_cache::CompressionMethod::Lzma2), // Use LZMA2\n    // Other options...\n};\n```\n\n### Per-Item Compression\n\nYou can override the default compression setting for individual items:\n\n```typescript\n// Force compression for this item regardless of default setting\nawait set('largeData', largeObject, { compress: true });\n\n// Force no compression for this item\nawait set('smallData', smallObject, { compress: false });\n\n// Use Zlib for faster compression\nawait set('mediumData', mediumObject, { compress: true, compressionMethod: CompressionMethod.Zlib });\n\n// Use LZMA2 for high compression ratio (useful for large text data)\nawait set('largeTextData', largeText, { compress: true, compressionMethod: CompressionMethod.Lzma2 });\n```\n\nWhen using the compression method feature, make sure to import the `CompressionMethod` enum along with the functions you need:\n\n```typescript\nimport { set, get, CompressionMethod } from 'tauri-plugin-cache-api';\n```\n\n### Compression Method Comparison\n\n| Method | Compression Ratio | Compression Speed | Decompression Speed | Best For |\n|--------|-------------------|-------------------|---------------------|----------|\n| Zlib   | Good              | Fast              | Fast                | General purpose, balanced performance |\n| LZMA2  | Excellent         | Slow              | Medium              | Base64 data, large text, maximum space saving |\n\nChoose LZMA2 when disk space is at a premium and you don't mind slower compression times. Zlib is better for general purpose use where compression/decompression speed is important.\n\n## Platform Compatibility\n\nThis plugin supports both desktop and mobile platforms:\n\n- Desktop: Windows, macOS, Linux\n- Mobile: Android, iOS\n\n## License\n\nThis project is released under the [MIT License](https://github.com/Taiizor/tauri-plugin-cache/blob/develop/LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTaiizor%2Ftauri-plugin-cache","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FTaiizor%2Ftauri-plugin-cache","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FTaiizor%2Ftauri-plugin-cache/lists"}