1.2.9 • Published 9 months ago

@hubspire/cache-directive v1.2.9

Weekly downloads
-
License
MIT
Repository
-
Last release
9 months ago

Cache Directive

A cache directive package for apollo graphql server for cache setting and cache invalidation. This package will help you to manage query caching.

Installation

Cache Directive Package requires Node.js v16+ to run.

Install the dependencies and devDependencies and start the server.

cd cache-directive
npm i
npm run build

How to implement ?

import { CacheContext } from "@hubspire/cache-directive";

export interface MyContext {
  cacheContext: CacheContext;
  ... // other context fields
}
import { CacheService, responseCachePlugin, cacheDirectiveTransformer } from "@hubspire/cache-directive";
import { makeExecutableSchema } from '@graphql-tools/schema';

const cacheService = await CacheService.start({
    cache_prefix: "cache_prefix",
    redis_host: String(process.env.REDIS_HOST),
    redis_port: Number(process.env.REDIS_PORT),
  });

const server = new ApolloServer<MyContext>({
  schema: cacheDirectiveTransformer(makeExecutableSchema({
    typeDefs,
    resolvers
  })),
  plugins: [
      responseCachePlugin<MyContext>()
  ],
  context: async ({ req }) => ({
    cacheContext: {
        cache: cacheService,
        sessionId: req?.headers?.authorization?.split(" ")[1] || null,
    },
  }),
});
directive @cacheSet(
  type: String!
  identifier: String!
  maxAge: Int = 900 # apply 900 seconds as the efault expire time for cache
) on FIELD_DEFINITION

input CachePurgeInput {
  types: [String!]!
  identifier: String
}
directive @cachePurge(payloads: [CachePurgeInput!]!) on FIELD_DEFINITION

License

MIT

Free Software, Hell Yeah!

1.2.8

9 months ago

1.2.7

10 months ago

1.2.6

10 months ago

1.2.9

9 months ago

1.2.5

1 year ago

1.2.4

1 year ago

1.2.3

1 year ago

1.2.2

1 year ago

1.2.0

1 year ago

1.1.9

1 year ago

1.1.8

1 year ago

1.2.1

1 year ago

1.1.7

1 year ago

1.1.6

1 year ago

1.1.5

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago