Comments (5)
https://github.com/sebringrose/peko/releases/tag/1.7.3 🎉
from peko.
Or.. maybe it'd be better to let the user create a suffix for the cache key by exposing the ctx
on the cacher()
?
Current
Additions
function parameter | key suffix |
---|---|
id: (ctx: RequestContext) => string |
-${id(ctx)} |
Future
export const cacher = (cache: ResponseCache, id: (ctx: RequestContext) => string): Middleware => async (ctx, next) => {
const reqURL = new URL(ctx.request.url)
const key = `${reqURL.pathname}${reqURL.search}-${JSON.stringify(ctx.state)}-${id(ctx)}`
from peko.
Excellent catch and thanks for the detailed issue.
The request method should definitely be in the CacheItem
key, I think it used to be but has maybe been removed. Either that or this has been a long-standing oversight.
I also like the idea of the optional key generator argument.
Suggested fix:
export const cacher = (cache: ResponseCache, keyGen?: (ctx: RequestContext) => string): Middleware => async (ctx, next) => {
const key = keyGen
? keyGen(ctx)
: `${ctx.request.method}-${ctx.request.url.pathname}${ctx.request.url.search}-${JSON.stringify(ctx.state)}`
Would you be interested in submitting a PR for this? Would be great to have you as a contributer :)
from peko.
Would you be interested in submitting a PR for this?
Yea, sure.
@sebringrose Are there any specific formatting guidelines for this repo?
from peko.
Basic formatting guidelines: (not enforced by linter, just habits I picked up from Deno docs)
- only include
;
semicolon where necessary - always use
"
double quotes instead of'
single quotes
You'll see requested changes on the PR. I realised we can define the default keygen function outside of the cacher for a minor performance boost.
from peko.
Related Issues (20)
- server.addRoutes(router.routes) misses async routes HOT 1
- lots of readdir boilerplate in server / router files - util for that? HOT 1
- documented param `onError` missing on `listen` function HOT 3
- `hostname` passed to `Server` does not apply to `stdServer` HOT 1
- Angular-like HTML Templating HOT 1
- Remove Deno namespace references HOT 1
- Replace imports from `deno/std` with engine agnostic `node:[library]` imports or custom helper utils HOT 1
- Helpers subdirectory
- calling next without `await` breaks cascade.
- Hot-Reload with file change emitter in ssrHandler (devMode) HOT 1
- Refactor cacher middleware to use Cache API
- Full API Documentation
- Fix Vue Example HOT 3
- ssrHandler - cache based on params as well as route string
- Eta-templating example broken as eta converts "<" to "<" HOT 1
- Test Middleware and Handler of Routes for common security pitfalls (devMode) HOT 1
- error from you example preact : deno version 1.24.3 HOT 5
- Use better dependency cdn for Preact example as reversehttp is slow HOT 2
- File watch handler that wraps SSE to emit events when files change.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from peko.