Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"baseBranch": "canary",
"updateInternalDependencies": "patch",
"ignore": [
"@neshca/server",
"@repo/backend",
"@repo/cache-handler-docs",
"@repo/cache-testing",
Expand Down
2 changes: 1 addition & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ updates:
open-pull-requests-limit: 20
ignore:
- dependency-name: 'lru-cache'
versions: ['11.x.x']
versions: ['>=11.0.0']
groups:
next-js:
patterns:
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:
- 'docs/cache-handler-docs/**'
- 'internal/eslint-config/**'
- 'package.json'
- 'biome.json'
- 'prettier.config.js'
jobs:
test:
Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ on:
- '.github/workflows/tests.yml'
- 'internal/eslint-config/**'
- 'package.json'
- 'biome.json'
- 'turbo.json'
- 'prettier.config.js'
pull_request:
Expand All @@ -28,7 +27,6 @@ on:
- '.github/workflows/tests.yml'
- 'internal/eslint-config/**'
- 'package.json'
- 'biome.json'
- 'turbo.json'
- 'prettier.config.js'
jobs:
Expand Down Expand Up @@ -68,7 +66,7 @@ jobs:
- name: Replace Path with Sed
run: |
if [ "${{ matrix.handler }}" == "redis-strings" ]; then
sed -i 's/cache-handler-redis-stack/cache-handler-redis-strings/g' apps/cache-testing/next.config.mjs
sed -i 's/cache-handler-redis-stack/cache-handler-redis-strings/g' apps/cache-testing/next.config.ts
sed -i 's/cache-handler-redis-stack/cache-handler-redis-strings/g' apps/cache-testing/src/instrumentation.ts
fi

Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ yarn-error.log*
# Misc
.DS_Store
*.pem

# TypeScript build info
tsconfig.tsbuildinfo
tsconfig.build.tsbuildinfo
13 changes: 3 additions & 10 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Dependencies
node_modules
pnpm-lock.yaml
.pnp
.pnp.js

Expand Down Expand Up @@ -36,13 +37,5 @@ yarn-error.log*
# Misc
.DS_Store
*.pem


# biome formatted files
*.js
*.ts
*.tsx
*.jsx
*.cjs
*.mjs
*.mts
tsconfig.tsbuildinfo
tsconfig.build.tsbuildinfo
1 change: 0 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{
"recommendations": [
"biomejs.biome",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"unifiedjs.vscode-mdx",
Expand Down
26 changes: 9 additions & 17 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,10 @@
}
],
"typescript.surveys.enabled": false,
"typescript.tsdk": "node_modules/typescript/lib",
"explorer.fileNesting.enabled": true,
"explorer.fileNesting.patterns": {
"*.ts": "$(capture).test.ts, $(capture).test.tsx",
"*.tsx": "$(capture).test.ts, $(capture).test.tsx"
},
"cSpell.words": ["nextjs", "prerendered", "codestyle"],
"grammarly.selectors": [
{
"language": "markdown",
"scheme": "file"
}
],
// "typescript.tsdk": "node_modules/typescript/lib",
"editor.defaultFormatter": "biomejs.biome",
"editor.defaultFormatter": "esbenp.prettier-vscode",
"[jsonc]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
Expand All @@ -39,16 +29,18 @@
"editor.wordWrap": "on"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[javascriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"[typescriptreact]": {
"editor.defaultFormatter": "biomejs.biome"
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"grammarly.files.include": ["**/*.md", "**/*.mdx"]
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check

import { CacheHandler } from '@neshca/cache-handler';
import createLruHandler from '@neshca/cache-handler/local-lru';
import createLruHandler from '@neshca/cache-handler/handlers/local-lru';

CacheHandler.onCreation(() => {
const localHandler = createLruHandler();
Expand Down
9 changes: 3 additions & 6 deletions apps/cache-testing/cache-handler-next-example.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
const cache = new Map();

module.exports = class CacheHandler {
export default class CacheHandler {
constructor(options) {
this.options = options;
}

// biome-ignore lint/suspicious/useAwait: don't bother
async get(key) {
// This could be stored anywhere, like durable storage
return cache.get(key);
}

// biome-ignore lint/suspicious/useAwait: don't bother
async set(key, data, ctx) {
// This could be stored anywhere, like durable storage
cache.set(key, {
Expand All @@ -21,15 +19,14 @@ module.exports = class CacheHandler {
});
}

// biome-ignore lint/suspicious/useAwait: don't bother
async revalidateTag(tag) {
// Iterate over all entries in the cache
// biome-ignore lint/style/useConst: don't bother

for (let [key, value] of cache) {
// If the value's tags include the specified tag, delete this entry
if (value.tags.includes(tag)) {
cache.delete(key);
}
}
}
};
}
19 changes: 19 additions & 0 deletions apps/cache-testing/cache-handler-none.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// @ts-check

import { CacheHandler } from '@neshca/cache-handler';

CacheHandler.onCreation(() => {
return {
handlers: [
{
name: 'handler-none',
get: () => Promise.resolve(undefined),
set: () => Promise.resolve(undefined),
revalidateTag: () => Promise.resolve(undefined),
delete: () => Promise.resolve(undefined),
},
],
};
});

export default CacheHandler;
22 changes: 7 additions & 15 deletions apps/cache-testing/cache-handler-redis-stack.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// @ts-check

const { CacheHandler } = require('@neshca/cache-handler');
const createLruHandler = require('@neshca/cache-handler/local-lru').default;
const createRedisHandler = require('@neshca/cache-handler/redis-stack').default;
const { createClient } = require('redis');
import { CacheHandler } from '@neshca/cache-handler';
import createLruHandler from '@neshca/cache-handler/handlers/local-lru';
import createRedisHandler from '@neshca/cache-handler/handlers/redis-stack';
import { createClient } from 'redis';

CacheHandler.onCreation(async () => {
if (!process.env.REDIS_URL) {
Expand All @@ -17,6 +17,7 @@ CacheHandler.onCreation(async () => {
try {
// Create a Redis client.
client = createClient({
RESP: 2,
url: process.env.REDIS_URL,
name: `cache-handler:${process.env.PORT ?? process.pid}`,
});
Expand Down Expand Up @@ -45,16 +46,7 @@ CacheHandler.onCreation(async () => {

console.warn('Disconnecting the Redis client...');
// Try to disconnect the client to stop it from reconnecting.
client
.disconnect()
.then(() => {
console.info('Redis client disconnected.');
})
.catch(() => {
console.warn(
'Failed to quit the Redis client after failing to connect.',
);
});
client.destroy();
}
}

Expand Down Expand Up @@ -86,4 +78,4 @@ CacheHandler.onCreation(async () => {
};
});

module.exports = CacheHandler;
export default CacheHandler;
89 changes: 0 additions & 89 deletions apps/cache-testing/cache-handler-redis-stack.mjs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check

import { CacheHandler } from '@neshca/cache-handler';
import createRedisHandler from '@neshca/cache-handler/redis-strings';
import createRedisHandler from '@neshca/cache-handler/handlers/redis-strings';
import { createClient } from 'redis';

CacheHandler.onCreation(async () => {
Expand All @@ -15,6 +15,7 @@ CacheHandler.onCreation(async () => {

/** @type {import("redis").RedisClientType} */
const client = createClient({
RESP: 2,
url: process.env.REDIS_URL,
name: `cache-handler:${PREFIX}${process.env.PORT ?? process.pid}`,
});
Expand Down
2 changes: 1 addition & 1 deletion apps/cache-testing/cluster.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
apps: [
{
name: 'app',
Expand Down
Loading
Loading