is it a good practice to store JSON as a value in KV? for example key:"user_123", value:"{"credits":
is it a good practice to store JSON as a value in KV? for example key:"user_123", value:"{"credits":15,email:"az@gmail.com"} ?
await KV.get("key, "json") to have KV automagically parse it for you500 - Is there anything I can do? Is this normal?cacheTtl and kvCacheTtl to be high for low latency, but I dont want to have to wait for kvCacheTtl to expire to fetch the updated value if needed. Am I thinking about this right and do I have to just bite the bullet and have low cache ttl values?
typed-kv. npm i typed-kv. There are no other projects in the npm registry using typed-kv.
wrangler.tomlThe .ts file which has the .put

name = "newcron"
main = "src/index.ts"
compatibility_date = "2024-05-29"
[triggers]
crons = ["* */12 * * *"]
[[kv_namespaces]]
binding = "KV"
id = "b6783170bcde4c6f9d9e6152dc8d1027"
[ai]
binding = "AI"...
[[kv_namespaces]]
binding = "OAUTH_KV"
id = "..."
...export const onRequestGet: PagesFunction<Env> = async ({ request, env }) => {
const { OAUTH_KV } = env;
...
try {
const dateStamp = new Date().toUTCString();
await OAUTH_KV.put(`smt:${user_id}`, longToken, {
expirationTtl: expiresIn,
metadata: {
"added_in": dateStamp,
},
});
console.log(`Stored long-lived token for user ${user_id}.`);
} catch (e) {
console.log(`Error storing smt long-lived token: ${e}`);
}name="pages-name"
pages_build_output_dir = "dist"
compatibility_date = "2024-06-12"
[[kv_namespaces]]
binding = "OAUTH_KV"
id = "..."
[dev]
port = 3000
[env.production]
[env.production.vars]
PUBLIC_ENVIRONMENT = "production"
SOME_VAR = "BLA BLA"
[env.preview]
[env.preview.vars]
PUBLIC_ENVIRONMENT = "preview"
SOME_VAR = "BLA BLA"