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

Make cache type less strict #179

Merged
merged 1 commit into from
Oct 8, 2024
Merged

Conversation

klzns
Copy link
Contributor

@klzns klzns commented Sep 30, 2024

I'm using mnemonist/lru-map to store the cache in my node project, like so:

import { find, setCache } from 'geo-tz/dist/find-all';
import LRUMap from 'mnemonist/lru-map';

// geo-tz can hold a total of 21,000 items in memory, costing 1.5GB when full
// The LRUMap of 5,000 items limits its size to ~400MB
const cacheStore = new LRUMap(5000);

// We need to type-cast because the expected type is a Map
// but it only expects a map-like entity with get and set methods
setCache({ store: cacheStore as unknown as Map<string, any> });

I would like to remove this type-casting, otherwise, I get this error:

CleanShot 2024-09-30 at 11 48 56@2x

I created this PR to relax the cache type to something that accepts another map-like entity like the LRUMap.

After the changes introduced by this PR, my code looks like this instead:

import { find, setCache } from 'geo-tz/dist/find-all';
import LRUMap from 'mnemonist/lru-map';

// geo-tz can hold a total of 21,000 items in memory, costing 1.5GB when full
// The LRUMap of 5,000 items limits its size to ~400MB
const cacheStore = new LRUMap(5000);

setCache({ store: cacheStore });

@codecov-commenter
Copy link

codecov-commenter commented Sep 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.84%. Comparing base (6076f79) to head (5c17961).
Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #179      +/-   ##
==========================================
- Coverage   89.41%   83.84%   -5.58%     
==========================================
  Files           7        7              
  Lines         359      359              
  Branches       63       63              
==========================================
- Hits          321      301      -20     
  Misses         36       36              
- Partials        2       22      +20     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Owner

@evansiroky evansiroky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code seems good to me, but please revise your commits to use Conventional Commits.

@klzns
Copy link
Contributor Author

klzns commented Oct 7, 2024

@evansiroky ops, fixed!

@klzns klzns requested a review from evansiroky October 7, 2024 15:35
@evansiroky evansiroky merged commit d55121a into evansiroky:master Oct 8, 2024
2 of 3 checks passed
@evansiroky
Copy link
Owner

🎉 This PR is included in version 8.1.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@klzns klzns deleted the relax-type branch October 8, 2024 17:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants