# cache_demo **Repository Path**: kropachevpavel/cache_demo ## Basic Information - **Project Name**: cache_demo - **Description**: Example of using @netteam/cache ohpm package. - **Primary Language**: Unknown - **License**: MIT - **Default Branch**: master - **Homepage**: https://ohpm.openharmony.cn/#/en/detail/@netteam%2Fcache - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2025-02-05 - **Last Updated**: 2025-02-25 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Cache demo application ## Introduction The repository contains an application that allows testing the [@netteam/cache](https://ohpm.openharmony.cn/#/en/detail/@netteam%2Fcache) package and interacting with its persistent caching functionality. The app enables interaction with the file cache and provides metrics estimation. Below are some screenshots of the testing application. ![Cache demo 1](screenshots/cache-demo-1.png) ![Cache demo 2](screenshots/cache-demo-2.png) ![Cache demo 3](screenshots/cache-demo-3.png) ## Comparison of file-based and folder-based caches The cache package offers a hybrid cache that can be based on either file-based storage or folder-based storage. The folder-based approach assumes one file per item in the cache, while the file-based approach uses only two files for all cache items: one for data and the other for metadata. The test app helps in choosing which storage to use by allowing the running of several experiments with synthesized data on a cache using both types of persistent storage. The table below shows the main metrics collected during these experiments. Each experiment begins by synthesizing 1000 items, each with a randomly generated size of up to 307,200 bytes and random content. These items are stored using either a file-based or folder-based approach. The write-through policy is applied in all experiments, with 10 MB allocated to the in-memory cache. | Scenario | Performance indicator | Folder-based cache | File-based cache | |------------------------|------------------------------------|--------------------|------------------| | **write-read** | Time of 1000 writes, s | 3.766 | 2.281 | | | Time of 4000 random reads, s | 7.670 | 3.689 | | | Cache files size, bytes | 156641201 | 158735238 | | | User data size, bytes | 154596090 | 154596090 | | | File space usage ratio | 98.69% | 97.39% | | **write-rewrite-read** | Time of 1000 writes, s | 3.339 | 2.502 | | | Time of 1000 rewrites, s | 7.060 | 3.591 | | | Time of 1000 reads time, s | 2.079 | 0.837 | | | Cache files size, bytes | 154094102 | 161347196 | | | User data size, bytes | 153788570 | 153788570 | | | File space usage ratio | 99.80% | 95.32% | | **random-delete** | Time of 1000 writes, s | 2.936 | 2.180 | | | Time of 1000 random deletes, s | 1.506 | 0.701 | | | Cache files size, bytes | 58694965 | 159088903 | | | User data size after delete, bytes | 56648047 | 56648047 | | | File space usage ratio | 96.51% | 35.61% | In summary, in a typical cache scenario where data is rewritten, a file-based cache is preferable due to its better performance.