sawthinkar
Nebulex.Cache.to_map and Cache.get
iex> Blog.Cache.set 1, "value", ttl: 10
"value"
iex> Blog.Cache.set 2, "value", ttl: 10
"value"
iex> Blog.Cache.set 3, "value", ttl: 10
"value"
iex> Blog.Cache.to_map
%{1 => "value", 2 => "value", 3 => "value"}
iex> Blog.Cache.get 1
nil
iex> Blog.Cache.to_map
%{2 => "value", 3 => "value"}
Why is it that only after running Blog.Cache.get key, Blog.Cache.to_map is updated? How do I refresh the stored data? Are there any computer science concept related with on-memory cache involved?
Most Liked
outlog
since this deals with ttl (of 10 seconds) you should post a function akin to the one in the readme, that uses :timer.sleep and then tell us what the unexpected behaviour is:
# Now it is ready to be used from any other module. Here is an example:
defmodule MyApp.Test do
alias MyApp.Cache
alias Nebulex.Object
def test do
Cache.set "foo", "bar", ttl: 2
"bar" = Cache.get "foo"
true = Cache.has_key? "foo"
%Object{key: "foo", value: "bar"} = Cache.get "foo", return: :object
:timer.sleep(2000)
nil = Cache.get "foo"
nil =
"foo"
|> Cache.set("bar", return: :key)
|> Cache.delete(return: :key)
|> Cache.get
end
end
1
Popular in Questions
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database.
Dep...
New
I would like to know what is the best IDE for elixir development?
New
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
I have a list say
x = ["23gh", "56kh", "97mh"]
I would like to pass each element to Val in each iteration.
Say, in iteration 1 -------...
New
I tried installing
elixir 1.11.2
erlang 23.3.4
via asdf in my zsh shell. Enabled the versions locally and globally.
When I list them ...
New
Hello, I have map which I want to convert it to string like this:
the map:
%{last_name: "tavakkoli", name: "shahryar"}
the string I ne...
New
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: )
Hello all, this is ...
New
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work.
Or rather, not char, but a substr...
New
Other popular topics
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
Good day to you all.
I have been struggling to get a query involving like and ilike to work.
Can anyone assist me on this, please?
pro...
New
Hi all,
Trying to get some more clarity over utc_datetime and naive_datetime for Ecto:
https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
I have followed this StackOverflow post to install the specific version of Erlang.
And When I am running mix ecto.setup then getting fol...
New
I have an umbrella app.
Some of the apps inside depend on other apps in the umbrella, unsurprisingly.
I'm writing a test for one of t...
New
I’m working on defining a simple Ecto schema for a table (in PostGres), but I don’t see where I can define a column as NOT NULL. Conside...
New
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible.
total = 10
while total != 0
...
New
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Hey all,
I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New







