Giter VIP home page Giter VIP logo

Comments (4)

eugenehp avatar eugenehp commented on May 5, 2024 3

Hey Lee, @leebyron

Do you think this concept could be used on the level of the internal Cache Storage?

Thanks.

from dataloader.

leebyron avatar leebyron commented on May 5, 2024 2

@vieks is correct here. DataLoader's cache is purely a local (in memory per instance) cache. It is not a distributed cache like memcached.

Here is a rough example of how you might implement a "read through" distributed cache with DataLoader:

function loadValue(id) {
  return fastLoader.load(id).catch(err => slowLoader.load(id));
}

let fastLoader = new DataLoader(ids => batchLoadFromMemcache(ids));

let slowLoader = new DataLoader(ids => batchLoadFromSQL(ids).then(values => {
  writeToMemcache(ids, values); // fire and forget
  return values;
}));

from dataloader.

vieks avatar vieks commented on May 5, 2024

This is exactly the issue I have created #23 but I auto-closed it because it's silly.

The purpose of Dataloader is to prevent at most round trips generated by a data source (Redis, PostgreSQL, whatever...) induced by their network nature. So permitting to create a async remote cache goes against the benefit of using Dataloader hence becoming useless.

Strictly speaking Dataloader doesn't realy implement a cache but a memoize mechanism.

Furthermore, if you look at the source: _promiseCache: CacheMap<K, Promise<V>>;
Dataloader memoize/cache Promise objects, no pure raw data types, so you can't serialize them into a remote cache.

If you want a real cache in front of a slow data source/store/base, make it in an upstream batch function.

as it could be too much for just memory storage

Or at least use the custom cache api with an in-memory LRU local cache:

LRU node
LRU memoize

from dataloader.

stanogurnik avatar stanogurnik commented on May 5, 2024

@vieks it makes sense in how you put it, thank you for explanation & closing issue.

from dataloader.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.