valointranet / indexeddb-cache Goto Github PK
View Code? Open in Web Editor NEWCache implementation using IndexedDB
License: MIT License
Cache implementation using IndexedDB
License: MIT License
Hi,
I´m Using "@valo/cache": "0.0.1",
I have got this error
'CacheService' is not exported by ./node_modules/@valo/cache/dist/index.js
this is my TS file
import { IMenu } from "./../interfaces/appLists.interfaces";
import { Web } from "@pnp/sp/webs";
import "@pnp/sp/webs";
import "@pnp/sp/lists";
import "@pnp/sp/items";
import { SPFXutils } from "./../services/SPFXutils";
import { CacheService, DateHelper, DateInterval } from '@valo/cache';
export const useMenu = async () => {
(async () => {
await cache.init();
})();
const cache = new CacheService(menuhorizontal
);
const getMenu = async (): Promise<IMenu[]> => {
try {
return await cache.get(menuhorizontal
);
} catch (error) {
getItensPai().then(async (r) => {
await cache.put(menuhorizontal
, r, DateHelper.dateAdd(Date(), DateInterval.minute, 1));
return r;
});
}
};
const getItensPai = async(): Promise<IMenu[]> => {
try {
var menu: IMenu[] = [];
const w = Web(this.siteUrl);
const queryOptions = <QueryOptions><ViewAttributes Scope='RecursiveAll'/></QueryOptions>
;
var query = <Query><Where><IsNull><FieldRef Name="pai" /></IsNull></Where><OrderBy><FieldRef Name='SANOrdem1' Ascending='True' /></OrderBy></Query>
;
let r = await w.lists.getByTitle(this.listName).renderListDataAsStream({
ViewXml: <view>${query}${queryOptions}</view>
,
});
if (r.Row.length > 0) {
for (let i = 0; i < r.Row.length; i++) {
const element = r.Row[i];
//busca filho
var menufilho: IMenu[] = await getItensFilho(element.ID);
var item: IMenu = {
Id: element.ID,
Title: element.Title,
SANLink:
element.SANLinkMult != "" ? element.SANLinkMult : element.SANLink,
SANNewWindown: element.SANNewWindown,
SANOrdem1: element.SANOrdem1,
SANIcon: new SPFXutils().extractIMGUrl(element.SANIcon, "menu"),
Filho: menufilho,
isActive: element.SANLink === window.location.pathname,
openie: element.openIE,
};
menu.push(item);
}
}
return menu;
} catch (error) {
console.error(error);
}
}
const getItensFilho = async(pai: string): Promise<IMenu[]> => {
try {
var menufilho: IMenu[] = [];
const w = Web(this.siteUrl);
const queryOptions = <QueryOptions><ViewAttributes Scope='RecursiveAll'/></QueryOptions>
;
var query =
<Query><Where><Eq><FieldRef Name="pai" LookupId='TRUE' /><Value Type="Lookup">
+
pai +
</Value></Eq></Where><OrderBy><FieldRef Name='SANOrdem1' Ascending='True' /></OrderBy></Query>
;
let items = await w.lists
.getByTitle(this.listName)
.renderListDataAsStream({
ViewXml: <view>${query}${queryOptions}</view>
,
});
if (items.Row.length > 0) {
for (let i = 0; i < items.Row.length; i++) {
const element = items.Row[i];
var menusubfilho: IMenu[] = await getItensFilho(element.ID);
var item: IMenu = {
Id: element.ID,
Title: element.Title,
SANLink:
element.SANLinkMult != "" ? element.SANLinkMult : element.SANLink,
SANNewWindown: element.SANNewWindown,
SANOrdem1: element.SANOrdem1,
SANIcon: new SPFXutils().extractIMGUrl(element.SANIcon, "menu"),
Filho: menusubfilho,
isActive: element.SANLink === window.location.pathname,
openie: element.openIE,
};
menufilho.push(item);
}
}
return menufilho;
} catch (e) {
console.log(e);
}
}
return {
getMenu,
};
};
Hi Elio,
This is a nice wrapper for IndexedDB and is just what I needed recently. I've been able to Init a database and put a handful of data in it with put(). I can see the data in the browser dev tools and it all looks good. However, when I call get() with my cacheKey it gives me the error "Database doesn't exist.".
My example seems pretty simple. Initializing the service from the constructor like this:
public initCache = async () => {. this.cacheService = new CacheService(cacheDatabaseKey); await this.cacheService.init(); }
Then I try to retrieve it like this:
let cachedData = await this.cacheService.get(myCacheKey);
Any ideas?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.