Skip to content
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

Maybe get rid of lscache dependency #1556

Closed
srabraham opened this issue Jan 23, 2025 · 0 comments
Closed

Maybe get rid of lscache dependency #1556

srabraham opened this issue Jan 23, 2025 · 0 comments
Assignees

Comments

@srabraham
Copy link
Member

srabraham commented Jan 23, 2025

Currently our client code relies on four external dependencies: Bootstrap, DataTables, jQuery, lscache. lscache hasn't seen any updates in 3 years, and is a lesser known package.

I like severing dependencies wherever possible, and especially so in frontend code (as I mentioned in another issue recently, these are dependencies on the internet that we have while on-playa). We only made simple use of that lscache dependency in the first place (get and set), and I was able to write the below replacement very easily. I'd like to just replace the use of that external dependency with this code.

function storeLocal(key, value, ttlSeconds) {
    localStorage.setItem(`ims.${key}`, JSON.stringify(value));
    localStorage.setItem(`ims.${key}.deadline`, `${Date.now()+ttlSeconds*1000}`);
}

function retrieveLocal(key) {
    const val = localStorage.getItem(`ims.${key}`);
    const deadline = localStorage.getItem(`ims.${key}.deadline`);
    if (val == null || !deadline) {
        return null;
    }
    if (Date.now() > new Date(Number.parseInt(deadline))) {
        return null;
    }
    return JSON.parse(val);
}
@srabraham srabraham self-assigned this Jan 23, 2025
srabraham added a commit that referenced this issue Jan 24, 2025
External frontend dependencies kind of suck, and we were bringing in
lscache for a rather trivial use case. Let's just do it ourselves.

#1556
srabraham added a commit that referenced this issue Jan 24, 2025
External frontend dependencies kind of suck, and we were bringing in
lscache for a rather trivial use case. Let's just do it ourselves.

#1556
srabraham added a commit that referenced this issue Jan 24, 2025
External frontend dependencies kind of suck, and we were bringing in
lscache for a rather trivial use case. Let's just do it ourselves.

#1556
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant