Skip to content

Conversation

@pmosconi
Copy link

Hi @yxx4c ,
as you suggested, this is the PR for the next branch.

I'd like to thank you for the hard work you put in creating and maintaining this package.

Regarding the breaking change about the returned object, I have some thoughts based on my use cases, but I am going to open an issue for discussion because it doesn't belong here.

@yxx4c
Copy link
Owner

yxx4c commented May 13, 2025

Hi @pmosconi,

I have been thinking about this change and was wondering if it is the right thing to do, to maintain this within the core codebase. I am still not sure, but here is my thought: It would be better to give the users the ability to bring their own string transformation function, with no transformations applied by default. In the example, we can show one with something like lodash.snakecase.

Example:

import snakeCase from 'lodash.snakecase';

const config: CacheConfig = {
 ttl: 60, // Default Time-to-live for caching in seconds
  stale: 30, // Default Stale time after ttl in seconds
  auto, // Auto-caching options (configured above)
  logger, // Logger for cache events (configured above)
  transformer: {
    // Custom serialize and deserialize function for additional functionality if required
    deserialize: data => SuperJSON.parse(data),
    serialize: data => SuperJSON.stringify(data),
  },
  type: 'JSON', // Redis cache type, whether you prefer the data to be stored as JSON or STRING in Redis
  cacheKey: { // Inbuilt cache key configuration
    caseTransformer: snakeCase, // Provide a transformation function which accepts the raw string and returns the transformed string
    delimiter: '*', // Delimiter for keys (default value: ':')
    prefix: 'awesomeness', // Cache key prefix (default value: 'prisma')
  },
};

This is just an example, and I haven't tested it, but this is the thought process. If you would like to discuss this or the other changes coming up in v3, feel free to reach out to me on Discord (ID yxx4c).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants