mirror of
https://github.com/umami-software/umami.git
synced 2026-02-12 16:45:35 +01:00
Add 1 day cache limit to user/website/session
This commit is contained in:
parent
d43ab3e559
commit
06de67ec55
1 changed files with 16 additions and 7 deletions
|
|
@ -2,17 +2,20 @@ import { User, Website } from '@prisma/client';
|
||||||
import redis from '@umami/redis-client';
|
import redis from '@umami/redis-client';
|
||||||
import { getSession, getUserById, getWebsiteById } from '../queries';
|
import { getSession, getUserById, getWebsiteById } from '../queries';
|
||||||
|
|
||||||
const { fetchObject, storeObject, deleteObject } = redis;
|
const { fetchObject, storeObject, deleteObject, expire } = redis;
|
||||||
|
|
||||||
async function fetchWebsite(id): Promise<Website> {
|
async function fetchWebsite(id): Promise<Website> {
|
||||||
return fetchObject(`website:${id}`, () => getWebsiteById(id));
|
return fetchObject(`website:${id}`, () => getWebsiteById(id), 86400);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function storeWebsite(data) {
|
async function storeWebsite(data) {
|
||||||
const { id } = data;
|
const { id } = data;
|
||||||
const key = `website:${id}`;
|
const key = `website:${id}`;
|
||||||
|
|
||||||
return storeObject(key, data);
|
const obj = await storeObject(key, data);
|
||||||
|
await expire(key, 86400);
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteWebsite(id) {
|
async function deleteWebsite(id) {
|
||||||
|
|
@ -20,14 +23,17 @@ async function deleteWebsite(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchUser(id): Promise<User> {
|
async function fetchUser(id): Promise<User> {
|
||||||
return fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }));
|
return fetchObject(`user:${id}`, () => getUserById(id, { includePassword: true }), 86400);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function storeUser(data) {
|
async function storeUser(data) {
|
||||||
const { id } = data;
|
const { id } = data;
|
||||||
const key = `user:${id}`;
|
const key = `user:${id}`;
|
||||||
|
|
||||||
return storeObject(key, data);
|
const obj = await storeObject(key, data);
|
||||||
|
await expire(key, 86400);
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteUser(id) {
|
async function deleteUser(id) {
|
||||||
|
|
@ -35,14 +41,17 @@ async function deleteUser(id) {
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchSession(id) {
|
async function fetchSession(id) {
|
||||||
return fetchObject(`session:${id}`, () => getSession(id));
|
return fetchObject(`session:${id}`, () => getSession(id), 86400);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function storeSession(data) {
|
async function storeSession(data) {
|
||||||
const { id } = data;
|
const { id } = data;
|
||||||
const key = `session:${id}`;
|
const key = `session:${id}`;
|
||||||
|
|
||||||
return storeObject(key, data);
|
const obj = await storeObject(key, data);
|
||||||
|
await expire(key, 86400);
|
||||||
|
|
||||||
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deleteSession(id) {
|
async function deleteSession(id) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue