Giter VIP home page Giter VIP logo

Comments (4)

grizzly-monkey avatar grizzly-monkey commented on August 15, 2024

ets_cache:update(graph_cache,123,#graph{id = 123 , val=2342},fun() -> ok end)

from cache_tab.

zinid avatar zinid commented on August 15, 2024

The Val should be in the form of {ok, V} or error. If existing value in the cache matches Val then UpdateFun is not called. Otherwise UpdateFun is called and should return ok (otherwise the cache will not be updated).
Example 1: you want to write value a at key 1:

ets_cache:update(my_tab, 1, {ok, a}, fun() -> database_write(1, a), ok end).

In the example above database_write(1, a) is not called if there is already value a associated with the key 1.
Example 2: you want to delete value b associated with key 2:

ets_cache:update(my_tab, 2, error, fun() -> database_delete(2), ok end).

In this case function database_delete(2) won't be called if there is already error in the cache (i.e. 'miss' is associated with key 2 in the cache).

from cache_tab.

zinid avatar zinid commented on August 15, 2024

So, simply put, ets_cache:update() function serves two purposes:

  1. Writing/deleting database data with cache updates.
  2. Avoiding excessive writes/deletes of the same data.

from cache_tab.

grizzly-monkey avatar grizzly-monkey commented on August 15, 2024

Great .. and thanks @zinid

from cache_tab.

Related Issues (16)

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.