Home / Function/ put() — drizzle-orm Function Reference

put() — drizzle-orm Function Reference

Architecture documentation for the put() function in cache.ts from the drizzle-orm codebase.

Entity Profile

Dependency Diagram

graph TD
  ac7a72b9_8a56_d022_b35e_119e88a6e847["put()"]
  418ebf5b_65ad_1cd4_79ba_2c99e874ea49["UpstashCache"]
  ac7a72b9_8a56_d022_b35e_119e88a6e847 -->|defined in| 418ebf5b_65ad_1cd4_79ba_2c99e874ea49
  style ac7a72b9_8a56_d022_b35e_119e88a6e847 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

drizzle-orm/src/cache/upstash/cache.ts lines 149–189

	override async put(
		key: string,
		response: any,
		tables: string[],
		isTag: boolean = false,
		config?: CacheConfig,
	): Promise<void> {
		const isAutoInvalidate = tables.length !== 0;

		const pipeline = this.redis.pipeline();
		const ttlSeconds = config && config.ex ? config.ex : this.internalConfig.seconds;
		const hexOptions = config && config.hexOptions ? config.hexOptions : this.internalConfig?.hexOptions;

		if (!isAutoInvalidate) {
			if (isTag) {
				pipeline.hset(UpstashCache.tagsMapKey, { [key]: UpstashCache.nonAutoInvalidateTablePrefix });
				pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions);
			}

			pipeline.hset(UpstashCache.nonAutoInvalidateTablePrefix, { [key]: response });
			pipeline.hexpire(UpstashCache.nonAutoInvalidateTablePrefix, key, ttlSeconds, hexOptions);
			await pipeline.exec();
			return;
		}

		const compositeKey = this.getCompositeKey(tables);

		pipeline.hset(compositeKey, { [key]: response }); // Store the result with the tag under the composite key
		pipeline.hexpire(compositeKey, key, ttlSeconds, hexOptions); // Set expiration for the composite key

		if (isTag) {
			pipeline.hset(UpstashCache.tagsMapKey, { [key]: compositeKey }); // Store the tag and its composite key in the map
			pipeline.hexpire(UpstashCache.tagsMapKey, key, ttlSeconds, hexOptions); // Set expiration for the tag
		}

		for (const table of tables) {
			pipeline.sadd(this.addTablePrefix(table), compositeKey);
		}

		await pipeline.exec();
	}

Domain

Subdomains

Frequently Asked Questions

What does put() do?
put() is a function in the drizzle-orm codebase, defined in drizzle-orm/src/cache/upstash/cache.ts.
Where is put() defined?
put() is defined in drizzle-orm/src/cache/upstash/cache.ts at line 149.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free