Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to use module attributes when specifying a MFA cache within the decorator #191

Closed
suzdalnitski opened this issue Feb 6, 2023 · 2 comments

Comments

@suzdalnitski
Copy link
Contributor

Hi,

The following works:

@decorate cacheable(
            cache: {MyApp.Cache, :get_cache, []},
            key: @some_key,
            opts: [ttl: @cache_ttl]
          )
def some_func do

While the following fails:

@my_cache {MyApp.Cache, :get_cache, []}

@decorate cacheable(
            cache: @my_cache,
            key: @some_key,
            opts: [ttl: @cache_ttl]
          )
def some_func do

The error I'm getting is:

** (ArgumentError) you attempted to apply a function on {MyApp.Cache, :get_cache, []}. Modules (the first argument of apply) must always be an atom
(nebulex 2.4.2) lib/nebulex/caching.ex:827: Nebulex.Caching.run_cmd/5

Is this expected behaviour?

Thanks!

@cabol
Copy link
Owner

cabol commented Feb 7, 2023

Hey 👋 !! Yeah, that is expected because the :cache option is resolved in compilation time, so when you do something like cache: @my_cache in the decorator, since it is a constant, what is received in the decorator is the constant itself, means the cache will be that constant, not expanded value. However, this is something we can handle maybe in runtime, making this possible, Let me think about that option (handling the :cache option in runtime) and maybe create a separate ticket. In the meantime, yeah, it is an expected behaviour.

@suzdalnitski
Copy link
Contributor Author

That makes sense, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants