slonik-interceptor-query-cache 3.2.0 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +17 -1
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -42,7 +42,7 @@ If present, `$valueHash` is substituted with the hash of the parameter values.
42
42
 
43
43
  |Required|Format|Default|
44
44
  |---|---|---|
45
- |No|`/^(false|true)$/`|`false`|
45
+ |No|`/^(false\|true)$/`|`false`|
46
46
 
47
47
  If set to `true`, then `storage.set` is not invoked when query produces no results.
48
48
 
@@ -80,7 +80,11 @@ const pool = await createPool('postgres://', {
80
80
  }),
81
81
  ]
82
82
  });
83
+ ```
83
84
 
85
+ These are example queries:
86
+
87
+ ```ts
84
88
  // Caches the query results based on a combination of the query hash and the parameter value hash.
85
89
  await connection.any(sql`
86
90
  -- @cache-ttl 60
@@ -92,6 +96,18 @@ await connection.any(sql`
92
96
  code_alpha_2 = ${countryCode}
93
97
  `);
94
98
 
99
+ // Does not cache the result when query produces no results.
100
+ await connection.any(sql`
101
+ -- @cache-ttl 60
102
+ -- @cache-discard-empty true
103
+ SELECT
104
+ id,
105
+ code_alpha_2
106
+ FROM country
107
+ WHERE
108
+ code_alpha_2 = ${countryCode}
109
+ `);
110
+
95
111
  // Caches the query results based only on the parameter value hash.
96
112
  await connection.any(sql`
97
113
  -- @cache-ttl 60
package/package.json CHANGED
@@ -67,5 +67,5 @@
67
67
  "test:ava": "nyc ava --verbose --serial"
68
68
  },
69
69
  "typings": "./dist/src/index.d.ts",
70
- "version": "3.2.0"
70
+ "version": "3.3.0"
71
71
  }