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(8mo ago)311[1 PRs](https://github.com/krissss/phpspreadsheet-smart-cache/pulls)MITPHPPHP ^8.1

Since Aug 28Pushed 8mo 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 1mo 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

31

—

LowBetter than 68% of packages

Maintenance59

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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

263d 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

[predis/predis

A flexible and feature-complete Redis/Valkey client for PHP.

7.8k305.7M2.4k](/packages/predis-predis)[snc/redis-bundle

A Redis bundle for Symfony

1.0k39.4M67](/packages/snc-redis-bundle)[react/cache

Async, Promise-based cache interface for ReactPHP

444112.4M40](/packages/react-cache)[wp-media/wp-rocket

Performance optimization plugin for WordPress

7431.3M3](/packages/wp-media-wp-rocket)[illuminate/cache

The Illuminate Cache package.

12835.6M1.4k](/packages/illuminate-cache)[colinmollenhour/php-redis-session-abstract

A Redis-based session handler with optimistic locking

6325.6M14](/packages/colinmollenhour-php-redis-session-abstract)

PHPackages © 2026

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