Skip to content

Commit fc8090a

Browse files
committed
Remove cache
1 parent b4fb361 commit fc8090a

File tree

10 files changed

+8
-920
lines changed

10 files changed

+8
-920
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"name": "simple-jekyll-search",
3-
"version": "1.15.1",
4-
"description": "Fork of Simple Jekyll Search from https://github.com/christian-fei/Simple-Jekyll-Search",
3+
"version": "2.0.0",
4+
"description": "A simple JavaScript library to add search functionality to any Jekyll blog - Fast, lightweight, client-side search. Fork of Simple Jekyll Search from https://github.com/christian-fei/Simple-Jekyll-Search",
55
"main": "dest/simple-jekyll-search.js",
66
"type": "module",
77
"scripts": {
88
"cypress": "cypress",
99
"cypress:ci": "node scripts/start-jekyll.js & sleep 5 && cypress run",
1010
"cypress:run": "node scripts/start-jekyll.js && sleep 8 && cypress run; EXIT_CODE=$?; node scripts/kill-jekyll.js; exit $EXIT_CODE",
1111
"lint": "eslint . --ext .ts",
12+
"lint:fix": "eslint . --ext .ts --fix",
1213
"pretest": "yarn run lint",
1314
"build": "tsc && vite build && terser dest/simple-jekyll-search.js -o dest/simple-jekyll-search.min.js",
1415
"prebuild": "yarn run test",

src/SearchStrategies/SearchCache.ts

Lines changed: 0 additions & 115 deletions
This file was deleted.

src/SearchStrategies/search/findLiteralMatches.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ export function findLiteralMatches(text: string, criteria: string): MatchInfo[]
2424
const matches: MatchInfo[] = [];
2525

2626
for (const word of pattern) {
27+
if (!word || word.length === 0) continue;
28+
2729
let startIndex = 0;
2830
while ((startIndex = lowerText.indexOf(word, startIndex)) !== -1) {
2931
matches.push({

src/SearchStrategies/types.ts

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { SearchCache } from './SearchCache';
2-
31
export interface MatchInfo {
42
start: number;
53
end: number;
@@ -10,89 +8,29 @@ export interface MatchInfo {
108
export interface Matcher {
119
matches(text: string | null, criteria: string): boolean;
1210
findMatches?(text: string | null, criteria: string): MatchInfo[];
13-
clearCache?(): void;
14-
getCacheStats?(): { hitRate: number; size: number };
15-
}
16-
17-
interface CachedResult {
18-
matches: boolean;
19-
matchInfo: MatchInfo[];
2011
}
2112

2213
export class SearchStrategy implements Matcher {
2314
private readonly findMatchesFunction: (text: string, criteria: string) => MatchInfo[];
24-
private readonly cache: SearchCache<CachedResult>;
2515

26-
constructor(
27-
findMatchesFunction: (text: string, criteria: string) => MatchInfo[],
28-
cacheOptions?: { maxSize?: number; ttl?: number }
29-
) {
16+
constructor(findMatchesFunction: (text: string, criteria: string) => MatchInfo[]) {
3017
this.findMatchesFunction = findMatchesFunction;
31-
this.cache = new SearchCache<CachedResult>({
32-
maxSize: cacheOptions?.maxSize ?? 100,
33-
ttl: cacheOptions?.ttl ?? 60000
34-
});
3518
}
3619

3720
matches(text: string | null, criteria: string): boolean {
3821
if (text === null || text.trim() === '' || !criteria) {
3922
return false;
4023
}
4124

42-
const cacheKey = this.getCacheKey(text, criteria);
43-
const cached = this.cache.get(cacheKey);
44-
if (cached !== undefined) {
45-
return cached.matches;
46-
}
47-
48-
const matchInfo = this.findMatchesInternal(text, criteria);
49-
const result: CachedResult = {
50-
matches: matchInfo.length > 0,
51-
matchInfo
52-
};
53-
54-
this.cache.set(cacheKey, result);
55-
return result.matches;
25+
const matchInfo = this.findMatchesFunction(text, criteria);
26+
return matchInfo.length > 0;
5627
}
5728

5829
findMatches(text: string | null, criteria: string): MatchInfo[] {
5930
if (text === null || text.trim() === '' || !criteria) {
6031
return [];
6132
}
6233

63-
const cacheKey = this.getCacheKey(text, criteria);
64-
const cached = this.cache.get(cacheKey);
65-
if (cached !== undefined) {
66-
return cached.matchInfo;
67-
}
68-
69-
const matchInfo = this.findMatchesInternal(text, criteria);
70-
const result: CachedResult = {
71-
matches: matchInfo.length > 0,
72-
matchInfo
73-
};
74-
75-
this.cache.set(cacheKey, result);
76-
return result.matchInfo;
77-
}
78-
79-
private findMatchesInternal(text: string, criteria: string): MatchInfo[] {
8034
return this.findMatchesFunction(text, criteria);
8135
}
82-
83-
private getCacheKey(text: string, criteria: string): string {
84-
return `${text.length}:${criteria}:${text.substring(0, 20)}`;
85-
}
86-
87-
clearCache(): void {
88-
this.cache.clear();
89-
}
90-
91-
getCacheStats(): { hitRate: number; size: number } {
92-
const stats = this.cache.getStats();
93-
return {
94-
hitRate: stats.hitRate,
95-
size: stats.size
96-
};
97-
}
9836
}

tests/SearchStrategies/HybridSearchStrategy.test.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -142,23 +142,6 @@ describe('HybridSearchStrategy', () => {
142142
});
143143
});
144144

145-
describe('cache integration', () => {
146-
const strategy = new HybridSearchStrategy();
147-
148-
it('should use cache for repeated searches', () => {
149-
const matches1 = strategy.findMatches('hello world', 'hello');
150-
const matches2 = strategy.findMatches('hello world', 'hello');
151-
expect(matches1).toEqual(matches2);
152-
});
153-
154-
it('should clear cache', () => {
155-
strategy.findMatches('test', 'test');
156-
strategy.clearCache();
157-
const stats = strategy.getCacheStats();
158-
expect(stats.size).toBe(0);
159-
});
160-
});
161-
162145
describe('matches() method', () => {
163146
const strategy = new HybridSearchStrategy();
164147

0 commit comments

Comments
 (0)