Giter Club home page Giter Club logo

Comments (11)

hsluoyz avatar hsluoyz commented on May 16, 2024

Thanks for pointing this out. My initial plan is using a RWMutex, Enforcer.Enforce() will be protected with read lock and functions like Enforcer.AddRoleForUser() will be protected with write lock, what do you think?

from casbin.

japettyjohn avatar japettyjohn commented on May 16, 2024

For my use case this is workable. If anyone else has performance concerns and does not have the use case of dynamic policies etc. this could be made as a thin wrapper.

from casbin.

hsluoyz avatar hsluoyz commented on May 16, 2024

I have added a wrapper here: 9251d5d

from casbin.

japettyjohn avatar japettyjohn commented on May 16, 2024

This looks great and it dropped in without issues, after a bit of testing I'll go ahead and close this thread. Thanks!

from casbin.

e-nikolov avatar e-nikolov commented on May 16, 2024

The Safe variants of methods (ones that return an error instead of panic) aren't thread safe at the moment because they are not wrapped.

from casbin.

hsluoyz avatar hsluoyz commented on May 16, 2024

@e-nikolov , we have "Safe" methods and "Synced" enforcer. These are two different things. "Safe" methods return error instead of causing panic. "Synced" enforcer will provide thread safe. You should use this: https://github.com/casbin/casbin/blob/master/enforcer_synced.go

from casbin.

e-nikolov avatar e-nikolov commented on May 16, 2024

@hsluoyz I know that, but the safe methods are also available from the synced enforcer, however they are not thread safe because they are not wrapped with mutexes the way the non-safe methods are.

from casbin.

hsluoyz avatar hsluoyz commented on May 16, 2024

OK. So you need both safe methods and synced enforcer at the same time, right? We can add the enforcer_safe_synced.go file to implement those functions.

Can you send a PR for it? I can also do it but it may take several days.

from casbin.

hsluoyz avatar hsluoyz commented on May 16, 2024

BTW, you can also propose a new issue to claim this problem, as this issue has already been closed for long time.

from casbin.

e-nikolov avatar e-nikolov commented on May 16, 2024

I could make a PR. I am only thinking that in the current model, there are enforcer, enforcer_synced, enforcer_safe, enforcer_cached. So every time that a new combination of those is needed, methods would sort of have to be duplicated. Is it an option to use something like Functional Options, and be able to do this: casbin.NewEnforcer(casbin.Synced(), casbin.Cached())?

from casbin.

hsluoyz avatar hsluoyz commented on May 16, 2024

casbin.NewEnforcer(casbin.Synced(), casbin.Cached()) will make the constructor even complicated. Do we have a non-intrusive way to specify synced or cached? e.g., enforcer.enableCache(), enforcer.enableSync() ?

from casbin.

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.