Skip to content

Commit c095eb8

Browse files
committed
📘 feat: remove stat cache
1 parent d02a9fd commit c095eb8

File tree

4 files changed

+16
-13
lines changed

4 files changed

+16
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 1.4.3 - 13 Oct 2025
2+
Bug fix:
3+
- remove stat cache
4+
15
# 1.4.2 - 13 Oct 2025
26
Improvement:
37
- better caching mechanism

example/index.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import { staticPlugin } from '../src/index'
55
import html from '../public/html/index.html'
66

77
const app = new Elysia()
8-
.get('', html)
98
.use(
10-
staticPlugin({
11-
alwaysStatic: true
12-
})
9+
await staticPlugin()
1310
)
1411
.listen(3000)
1512

public/html/a.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>Home!!</title>
5+
</head>
6+
<body>
7+
<h1>A!</h1>
8+
</body>
9+
</html>

src/index.ts

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ export async function staticPlugin<const Prefix extends string = '/prefix'>({
5050

5151
const [fs, path] = builtinModule
5252

53-
const statCache = new LRUCache<string, Stats>()
5453
const fileCache = new LRUCache<string, Response>()
5554

5655
if (prefix === path.sep) prefix = '' as Prefix
@@ -256,14 +255,8 @@ export async function staticPlugin<const Prefix extends string = '/prefix'>({
256255
if (cache) return cache.clone()
257256

258257
try {
259-
let fileStat = statCache.get(pathName)
260-
if (!fileStat)
261-
try {
262-
fileStat = await fs.stat(pathName)
263-
statCache.set(pathName, fileStat)
264-
} catch {
265-
throw new NotFoundError()
266-
}
258+
const fileStat = await fs.stat(pathName).catch(() => null)
259+
if (!fileStat) throw new NotFoundError()
267260

268261
if (!indexHTML && fileStat.isDirectory())
269262
throw new NotFoundError()

0 commit comments

Comments
 (0)