MCPcopy
hub / github.com/drizzle-team/drizzle-orm / put

Method put

drizzle-orm/src/cache/upstash/cache.ts:149–189  ·  view source on GitHub ↗
(
		key: string,
		response: any,
		tables: string[],
		isTag: boolean = false,
		config?: CacheConfig,
	)

Source from the content-addressed store, hash-verified

147 }
148
149 override async put(
150 key: string,
151 response: any,
152 tables: string[],
153 isTag: boolean = false,
154 config?: CacheConfig,
155 ): Promise<void> {
156 const isAutoInvalidate = tables.length !== 0;
157
158 const pipeline = this.redis.pipeline();
159 const ttlSeconds = config && config.ex ? config.ex : this.internalConfig.seconds;
160 const hexOptions = config && config.hexOptions ? config.hexOptions : this.internalConfig?.hexOptions;
161
162 if (!isAutoInvalidate) {
163 if (isTag) {
164 pipeline.hset(UpstashCache.tagsMapKey, { [key]: UpstashCache.nonAutoInvalidateTablePrefix });
165 pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);
166 }
167
168 pipeline.hset(UpstashCache.nonAutoInvalidateTablePrefix, { [key]: response });
169 pipeline.hexpire(UpstashCache.nonAutoInvalidateTablePrefix, key, ttlSeconds, hexOptions);
170 await pipeline.exec();
171 return;
172 }
173
174 const compositeKey = this.getCompositeKey(tables);
175
176 pipeline.hset(compositeKey, { [key]: response }); // Store the result with the tag under the composite key
177 pipeline.hexpire(compositeKey, key, ttlSeconds, hexOptions); // Set expiration for the composite key
178
179 if (isTag) {
180 pipeline.hset(UpstashCache.tagsMapKey, { [key]: compositeKey }); // Store the tag and its composite key in the map
181 pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions); // Set expiration for the tag
182 }
183
184 for (const table of tables) {
185 pipeline.sadd(this.addTablePrefix(table), compositeKey);
186 }
187
188 await pipeline.exec();
189 }
190
191 override async onMutate(params: MutationOption) {
192 const tags = Array.isArray(params.tags) ? params.tags : params.tags ? [params.tags] : [];

Callers

nothing calls this directly

Calls 1

execMethod · 0.80

Tested by

no test coverage detected