Coder Social home page Coder Social logo

Comments (6)

Suor avatar Suor commented on August 15, 2024

You can try using queryset.cache(lock=True).

from django-cacheops.

BoHuang-aspecta avatar BoHuang-aspecta commented on August 15, 2024

So, does this issue that I mentioned indeed exist? I will try to reproduce the problem and attempt to solve it using lock = True. THX

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

I don't understand what did this mean "Thread B invalidates the cache but doesn’t actually clear anything".

About whether there issue exists I am not sure, you can try to create a test using before_after library - there is already one test using it.

from django-cacheops.

BoHuang-aspecta avatar BoHuang-aspecta commented on August 15, 2024

I don't understand what did this mean "Thread B invalidates the cache but doesn’t actually clear anything".

About whether there issue exists I am not sure, you can try to create a test using before_after library - there is already one test using it.

Because when Thread B invalidates the cache, Thread A's cache write operation hasn't completed yet. At that point, the cache is actually empty (assuming the initial state is empty).

In summary, could it happen that Thread B's cache invalidation occurs before Thread A writes to the cache, in a concurrent scenario?

I will try to use before_after lib to reproduce this issue. Thanks for your advice.

from django-cacheops.

BoHuang-aspecta avatar BoHuang-aspecta commented on August 15, 2024

I reproduced this issue using a concurrent approach.

I tried to solve it using lock = True, but it didn’t completely resolve the issue. Some requests still couldn’t retrieve data and resulted in errors. However, it doesn’t seem to cause the previous irrecoverable problem.

By using the invalidate_obj approach mentioned above, it seems to have completely resolved the issue, and there are no more errors.

from django-cacheops.

Suor avatar Suor commented on August 15, 2024

Actually looking a little bit more at problematic issue, it has concurrency issues outside of cache - the code does not have a transaction, doesn't set ._for_write = True for initial .get(). Using .get_or_create() should solve this problem too.

from django-cacheops.

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.