project setup with core files including configuration, package management, and basic structure. Added .gitignore, README, and various TypeScript types for CMS components. Implemented initial components and layouts for the application.
This commit is contained in:
32
middlelayer/plugins/responseCache.ts
Normal file
32
middlelayer/plugins/responseCache.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import ApolloServerPluginResponseCache from "@apollo/server-plugin-response-cache";
|
||||
import type { GraphQLRequestContext } from "@apollo/server";
|
||||
|
||||
/**
|
||||
* Response Caching Plugin für Apollo Server
|
||||
* Cached GraphQL Responses basierend auf Query und Variablen
|
||||
*/
|
||||
export const createResponseCachePlugin = () => {
|
||||
return ApolloServerPluginResponseCache({
|
||||
// Session-ID für User-spezifisches Caching
|
||||
sessionId: async (
|
||||
requestContext: GraphQLRequestContext<any>
|
||||
): Promise<string | null> => {
|
||||
// Optional: User-ID aus Headers oder Context
|
||||
const userId = requestContext.request.http?.headers.get("x-user-id");
|
||||
return userId || null;
|
||||
},
|
||||
|
||||
// Cache nur bei erfolgreichen Queries
|
||||
shouldWriteToCache: async (
|
||||
requestContext: GraphQLRequestContext<any>
|
||||
): Promise<boolean> => {
|
||||
const query = requestContext.request.query;
|
||||
|
||||
if (!query) return false;
|
||||
|
||||
// Cache nur bestimmte Queries
|
||||
const cacheableQueries = ["products", "pageSeo", "navigation", "page"];
|
||||
return cacheableQueries.some((q) => query.includes(q));
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user