Coder Social home page Coder Social logo

Comments (7)

sorentwo avatar sorentwo commented on June 14, 2024

Right you are! Working on a patch, will have it out soon.

from readthis.

sorentwo avatar sorentwo commented on June 14, 2024

@droberts84 This should be fixed now. Would you mind giving it a try from master and letting me know?

from readthis.

drobtravels avatar drobtravels commented on June 14, 2024

First of all, thanks for the quick fix!

This fixes the initial issue, however I found a related quirk. It appears it doesn't actually cache the nil value, but instead behaves similar to a cache miss. See the example below

def check_cache
  Rails.cache.fetch('foo') do
    puts 'miss'
    nil
  end
end

check_cache
# miss
# => nil

check_cache
# miss
# => nil

Personally I prefer this behavior, however its not consistent with other cache stores. Since nil is a valid cache value, you would not expect a cache miss for the second fetch. I tested this same code against memory_store which did not print miss.

from readthis.

sorentwo avatar sorentwo commented on June 14, 2024

Yes, I can see how that's a problem. In the case of a single fetch we could work around this by checking for existence rather than the return value. That approach won't work for the *multi methods though. There everything is fetched in bulk and the missing keys all come back as nil. It is technically possible to alter read_multi to check keys before fetching, but it makes the method more complex and certainly slower. I'm not sure that I am willing to accept that trade off right now.

This may be a quirk that needs to be documented and lived with. What do you think?

from readthis.

drobtravels avatar drobtravels commented on June 14, 2024

Sounds good to me. This quirk actually works in my favor (fetch will
miss and cause a retry, which is generally desirable). Are you keeping the
current behavior in single fetch or adding the workaround? Personally I
think consistency among both methods would be best, even if its not the
standard, but that is of course your call.

Thanks again for your quick action on this issue.

On Thu, Sep 3, 2015 at 1:24 PM Parker Selbert [email protected]
wrote:

Yes, I can see how that's a problem. In the case of a single fetch we
could work around this by checking for existence rather than the return
value. That approach won't work for the *multi methods though. There
everything is fetched in bulk and the missing keys all come back as nil.
It is technically possible to alter read_multi to check keys before
fetching, but it makes the method more complex and certainly slower. I'm
not sure that I am willing to accept that trade off right now.

This may be a quirk that needs to be documented and lived with. What do
you think?


Reply to this email directly or view it on GitHub
#15 (comment).

from readthis.

sorentwo avatar sorentwo commented on June 14, 2024

I definitely want to keep consistency between the fetch methods. In this case that means ignoring nil for fetch and fetch_multi.

from readthis.

Napolskih avatar Napolskih commented on June 14, 2024

Hi
I am also concerned about the problem of "caching nil". Maybe solve this problem by caching NullObject, by analogy with the way it's done here:
petergoldstein/dalli#559

I honestly do not understand the problem with the fetch_multi.

In my opinion, the fact that an empty value is not cached reduces the efficiency of the application.

from readthis.

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.