PHPackages                             kriss/spreadsheet-smart-cache - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. kriss/spreadsheet-smart-cache

ActiveLibrary[Caching](/categories/caching)

kriss/spreadsheet-smart-cache
=============================

Spreadsheet Smart Cache For Balance memory and speed

v1.0.0(11mo ago)371[1 PRs](https://github.com/krissss/phpspreadsheet-smart-cache/pulls)MITPHPPHP ^8.1

Since Aug 28Pushed 11mo agoCompare

[ Source](https://github.com/krissss/phpspreadsheet-smart-cache)[ Packagist](https://packagist.org/packages/kriss/spreadsheet-smart-cache)[ RSS](/packages/kriss-spreadsheet-smart-cache/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

简介
==

[](#简介)

一个专为 [PHPSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet) 设计的智能缓存机制，用于优化和平衡大文件处理时的内存使用和性能问题。

> 简体中文(zh-cn) | [English](./README_en.md)

安装
==

[](#安装)

```
composer require kriss/spreadsheet-smart-cache
```

使用方法
====

[](#使用方法)

详细介绍请参见官方文档：[PhpSpreadsheet Memory Saving](https://phpspreadsheet.readthedocs.io/en/latest/topics/memory_saving/)

```
$yourLocalPath = __DIR__ . '/' . uniqid('spreadsheet_smart_cache_');
$cache = new \Kriss\SpreadsheetSmartCache\SpreadsheetSmartCache($yourLocalPath);

\PhpOffice\PhpSpreadsheet\Settings::setCache($cache);
```

> **注意**：为避免多并发情况下缓存目录冲突，`$yourLocalPath` 建议应该执行时都不相同。

设计思路与优势
=======

[](#设计思路与优势)

### 为什么不使用 APCu、Redis、MemCache？

[](#为什么不使用-apcuredismemcache)

- **APCu** 仍然占用服务器内存，与直接使用内存几乎没有区别，且 PhpSpreadsheet 本身并无跨进程缓存共享的必要。
- **Redis/MemCache** 只是在将内存压力转移到外部服务。当处理大文件及高并发时，极易导致外部缓存服务内存压力过大、性能下降。

### 为什么推荐文件缓存？

[](#为什么推荐文件缓存)

- 处理超大、多个并发的电子表格时，文件缓存几乎可以认为空间无限，更适合大规模数据处理场景。

### 为什么不直接用常规文件缓存（如 Symfony/cache 或 illuminate/cache 的文件缓存）？

[](#为什么不直接用常规文件缓存如-symfonycache-或-illuminatecache-的文件缓存)

- 这些方案通常是“一个 key 一个文件”的存储模式。
- 处理大量单元格时，会产生海量零碎小文件，频繁读写极大影响性能。

### SmartCache 的优化点？

[](#smartcache-的优化点)

- **批量存储**：多个 Cells 共用单一文件缓存，减少文件操作。
- **分块存储**：采用 ChunkSize 分块，提升空间利用效率，减少磁盘浪费。
- **高效读写**：通过文件 seek 实现偏移读写，避免大量小文件操作。
- **标记与统一处理**：删除等操作时，仅标记删除位，最终直接删除整个目录。

性能测试
====

[](#性能测试)

测试机器：macos M4 16G SSD

php: 8.2

phpoffice/phpspreadsheet: 5.0

单元格范围是否使用 SmartCache耗时（秒）memory\_peak（M）A1:Z1000N0.55717818.00A1:Z1000Y0.89342412.00A1:Z10000N5.465772120.00A1:Z10000Y8.86170148.00A1:Z20000N11.333312236.00A1:Z20000Y18.62774690.00A1:Z30000N16.654778380.00A1:Z30000Y27.586086152.00A1:CZ10000N21.779006468.00A1:CZ10000Y36.568663174.00可通过 [scripts/benchmark.php](scripts/benchmark.php) 脚本测试实际性能表现。

###  Health Score

30

—

LowBetter than 61% of packages

Maintenance50

Moderate activity, may be stable

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

355d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b4053cfc9956b8c15b9bc4c9c7c2bad625d16d1b6d9191019b2a25cc0972d955?d=identicon)[kriss](/maintainers/kriss)

---

Top Contributors

[![krissss](https://avatars.githubusercontent.com/u/10680903?v=4)](https://github.com/krissss "krissss (6 commits)")

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/kriss-spreadsheet-smart-cache/health.svg)

```
[![Health](https://phpackages.com/badges/kriss-spreadsheet-smart-cache/health.svg)](https://phpackages.com/packages/kriss-spreadsheet-smart-cache)
```

###  Alternatives

[iazaran/smart-cache

Smart Cache is a caching optimization package designed to enhance the way your Laravel application handles data caching. It intelligently manages large data sets by compressing, chunking, or applying other optimization strategies to keep your application performant and efficient.

21114.2k](/packages/iazaran-smart-cache)[phpfastcache/phpssdb

PHP SSDB Driver for phpFastCache

14736.9k1](/packages/phpfastcache-phpssdb)[rapidwebltd/rw-file-cache

RW File Cache is a PHP File-based Caching Library. Its syntax is designed to closely resemble the PHP memcache extension.

15196.8k7](/packages/rapidwebltd-rw-file-cache)[yuzuru-s/redis-recommend

Wrapping Redis's sorted set APIs for specializing recommending operations.

392.9k](/packages/yuzuru-s-redis-recommend)[ichhabrecht/intcache

Turn uncachable page objects into cacheable links

193.9k](/packages/ichhabrecht-intcache)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
