-
-
Notifications
You must be signed in to change notification settings - Fork 935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache isn't working #873
Comments
Please, don't kill us. We won't rewrite your code character by character. Copy and paste it here, otherwise the issue will be closed. |
import DTConstants from "@/protocol/DTConstants";
import { stringify } from "querystring";
import { Languages } from "@/configurations/language/Languages";
import got from "got";
import { appDataPath } from "@lazyspace/common";
import KeyvFile from "keyv-file";
import { join } from "path";
import { Data } from "./data";
const cache = new KeyvFile({
filename: join(appDataPath, "data.json"), // the file path to store the data
expiredCheckDelay: 10 * 24 * 3600 * 1000, // ms, check and remove expired data in each ms
writeDelay: 120, // ms, batch write to disk in a specific duration, enhance write performance.
encode: JSON.stringify, // serialize function
decode: JSON.parse // deserialize function
});
export interface RequestData {
lang?: Languages;
id?: string | number;
ids?: (string | number)[];
class?: keyof Data;
}
export async function request<T extends unknown>(
serverPath: string,
path: string,
data: RequestData,
defaultLang: Languages
): Promise<T> {
const query = {
lang: data.lang || defaultLang,
v: DTConstants.buildVersion
};
const req = serverPath + path + "?" + stringify(query);
const { body } = await got.post(req, {
cache,
retry: 4,
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify(data),
responseType: "json"
});
return body;
} Sorry for that |
What URL were you trying to cache? |
I get |
A simple POST request with the Content-Type header with this in body: {
"class": "Pets",
"ids": []
} |
Is this specific for |
It doesn't work either |
So the method is POST, and what's the status code? |
200 |
And what are the response headers? |
I don't see any outstanding behavior. It works as expected. https://httpwg.org/specs/rfc7234.html#rfc.section.4.4
|
I think what you're looking for is #875 |
Oh I was thinking it would store the response body in the cache if the request doesn't change. Like params etc |
Describe the bug
Actual behavior
When I put a cache system it does not work. I'm currently using master branch, and different module like
keyv-file
and the file is never saved.Expected behavior
The file is here and used in case of subsequent request.
Code to reproduce
Checklist
The text was updated successfully, but these errors were encountered: