mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: add force cache
This commit is contained in:
parent
479f90aefb
commit
0bc1391148
3 changed files with 15 additions and 1 deletions
5
packages/pjax/index.d.ts
vendored
5
packages/pjax/index.d.ts
vendored
|
|
@ -179,6 +179,11 @@ declare namespace Pjax {
|
|||
requestParams?: IRequestParams[];
|
||||
formData?: FormData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cache accessed pages
|
||||
*/
|
||||
forceCache?: boolean
|
||||
}
|
||||
|
||||
export type Switch = (oldEl: Element, newEl: Element, options?: IOptions, switchesOptions?: StringKeyedObject) => void;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ var Pjax = function(options) {
|
|||
this.log("Pjax options", this.options);
|
||||
|
||||
if (this.options.scrollRestoration && "scrollRestoration" in history) {
|
||||
history.scrollRestoration = "manual";
|
||||
history.scrollRestoration = "auto";
|
||||
}
|
||||
|
||||
this.maxUid = this.lastUid = newUid();
|
||||
|
|
|
|||
|
|
@ -1,8 +1,11 @@
|
|||
var updateQueryString = require("./util/update-query-string");
|
||||
|
||||
const cache = new Map();
|
||||
|
||||
module.exports = function(location, options, callback) {
|
||||
options = options || {};
|
||||
var queryString;
|
||||
var forceCache = options.forceCache || false;
|
||||
var requestOptions = options.requestOptions || {};
|
||||
var requestMethod = (requestOptions.requestMethod || "GET").toUpperCase();
|
||||
var requestParams = requestOptions.requestParams || null;
|
||||
|
|
@ -11,9 +14,15 @@ module.exports = function(location, options, callback) {
|
|||
var request = new XMLHttpRequest();
|
||||
var timeout = options.timeout || 0;
|
||||
|
||||
if (forceCache && cache.has(location)) {
|
||||
callback(cache.get(location), request, location, options);
|
||||
return;
|
||||
}
|
||||
|
||||
request.onreadystatechange = function() {
|
||||
if (request.readyState === 4) {
|
||||
if (request.status === 200) {
|
||||
if (forceCache) cache.set(location, request.responseText);
|
||||
callback(request.responseText, request, location, options);
|
||||
} else if (request.status !== 0) {
|
||||
callback(null, request, location, options);
|
||||
|
|
|
|||
Loading…
Reference in a new issue