BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
2.04k stars 215 forks source link

[BUG] issue with caching and statemanagement #732

Closed CAPITAINMARVEL closed 10 months ago

CAPITAINMARVEL commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

To Reproduce

class Sample(Document):
    num: int
    name: str

    class Settings:
        use_state_management = True
        use_cache = True

        doc_test = Sample(num=500, name= "Test")
        await doc_test.create()
        s = await Sample.find_one(Sample.name == "Test")
        assert s
        s.num = 1000
        await s.save_changes()
        print(await Sample.find_one(Sample.name == "Test"))

Expected behavior on the new document i should get it with 1000 instead of 500 but it doesnt keep track and it stay the same from cache

CAPITAINMARVEL commented 1 year ago

?

roman-right commented 1 year ago

Hi @CAPITAINMARVEL, This is the expected behavior. I plan to add a method to invalidate the cache. However, implementing the updating of cached results based on the database's update operations is not on the to-do list.

github-actions[bot] commented 11 months ago

This issue is stale because it has been open 30 days with no activity.

github-actions[bot] commented 10 months ago

This issue was closed because it has been stalled for 14 days with no activity.

xtay commented 8 months ago

Hi @CAPITAINMARVEL, This is the expected behavior. I plan to add a method to invalidate the cache. However, implementing the updating of cached results based on the database's update operations is not on the to-do list.

Agree with CAPITAINMARVEL.

I don't think this behavior is ok for a "cache", a "cache" should no be a distraction. it should do its work and give results as if it were not there(just be faster or reduce io). it would be great if "cache invalidation" could be implemented, and it would be even better if you could make it the default action while invoking any modification methods.

BTW, this repo is EXTREMELY GREAT, THANKS