Concahe's weird behaviour on ConCache.get

I am using ConCahe for saving an image with its modified timestamps. It works fine, normally, and when I say normally then it works fine in logs as

  def update_cache_and_save_thumbnail(camera_exid, timestamp, image) do
    {last_save_date, t, img} = ConCache.dirty_get_or_store(:camera_thumbnail, camera_exid, fn() ->
      {Calendar.DateTime.now!("UTC"), timestamp, image}
    end)
    Logger.info "This is dirty get or store"
    IO.inspect ConCache.get(:camera_thumbnail, camera_exid)
    Logger.info "==========================="
    case Calendar.DateTime.diff(Calendar.DateTime.now!("UTC"), last_save_date) do
      {:ok, seconds, _, :after} ->
        thumbnail_save_seaweedfs(camera_exid, image, timestamp, last_save_date, seconds)
        Logger.info "This is after thumnail save_seaweedfs"
        IO.inspect ConCache.get(:camera_thumbnail, camera_exid)
        Logger.info "==========================="
      _ ->
        Logger.info "This is will never run i think"
        IO.inspect ConCache.get(:camera_thumbnail, camera_exid)
        Logger.info "==========================="
        ConCache.dirty_put(:camera_thumbnail, camera_exid, {last_save_date, timestamp, image})
    end
  end

when this function run and I am calling ConCache.get(:camera_thumbnail, "blessington_court") in between and it’s giving me an updated value right away. such as

[info] This is dirty get or store
{#DateTime<2018-10-09 06:58:37.474918+00:00 UTC UTC>, 1539067937,
 <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255,
   254, 0, 15, 10, 1, 91, 188, 80, 34, 11, 91, 188, 80, 34, 11, 1, 255, 254, 0,
   15, 10, 0, 1, 219, 5, 80, ...>>}
[info] ===========================
{#DateTime<2018-10-09 06:58:37.474918+00:00 UTC UTC>, 1539067919,
 <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255,
   254, 0, 15, 10, 1, 91, 188, 80, 21, 58, 91, 188, 80, 21, 58, 1, 255, 254, 0,
   15, 10, 0, 1, 219, 5, 80, ...>>}
[info] This is after thumnail save_seaweedfs
[info] ===========================
[info] This is dirty get or store
{#DateTime<2018-10-09 06:58:37.474918+00:00 UTC UTC>, 1539067919,
 <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255,
   254, 0, 15, 10, 1, 91, 188, 80, 21, 58, 91, 188, 80, 21, 58, 1, 255, 254, 0,
   15, 10, 0, 1, 219, 5, 80, ...>>}
[info] ===========================
{#DateTime<2018-10-09 06:58:37.474918+00:00 UTC UTC>, 1539067934,
 <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255,
   254, 0, 15, 10, 1, 91, 188, 80, 31, 78, 91, 188, 80, 31, 78, 1, 255, 254, 0,
   15, 10, 0, 1, 219, 5, 80, ...>>}
[info] This is after thumnail save_seaweedfs
[info] ==========================

for once it gives duplicate but that’s because it’s been looking in cache. but whenever I do in the remote console as ConCache.get(:camera_thumbnail, “blessington_court”), It always gives the very old value. not the updated one.

{#DateTime<2018-10-09 06:25:56.691951+00:00 UTC UTC>, 1539065928,
 <<255, 216, 255, 224, 0, 16, 74, 70, 73, 70, 0, 1, 2, 0, 0, 1, 0, 1, 0, 0, 255,
   254, 0, 15, 10, 1, 91, 188, 72, 63, 84, 91, 188, 72, 63, 84, 1, 255, 254, 0,
   15, 10, 0, 1, 219, 5, 80, ...>>}

I have read the module docs for concache, But I didn’t find anything suitable which can pas the theory that it will give new value right away but old one when I can method by myself.? Can you guide me what is wrong happening in this? I tried this several times but it’s giving me an old value always.

Hi @ijunaidfarooq,

The forum is a place for the community to talk and help the community. You have absolutely no guarantee you will get a reply, because all of us are here on our free time and we answer things based on our interest, schedule, etc.

For this reason, it is also considered rude to just bump/ping your threads just a few hours after they have been posted. I bet there are other people asking questions too and eager for answers. Imagine if everyone was bumping their threads every three hours? It would quickly get unmanageable. I would recommend to wait at least 24h.

So my suggestion is for you to be a bit more patient. Meanwhile, if you want to, you can visit other threads in the forum and see if there is anything that you can answer and contribute to! I am sure there are developers stuck on different problems and your feedback could help them move forward.

3 Likes

For note, the author of ConCache states that Cachex should probably be used for any new projects as it is more tested and feature-full, but he’ll keep using his for his own work as it’s pretty well customized for his use.

And yes, these forums at about this time is when more people are waking up, there are more of us if you wait. :slight_smile:

Consequently though I know how Cachex works pretty well since I use it a lot, I don’t know well how ConCourse work so I can’t really say about this issue…

Okay but issue only here is: When the process is running. its updating the value, IO.inspect is telling a story. but when I call the same method in remote console, it tells different I am only looking for some possibilities or hunches which may give me some directions.

@josevalim Sorry for trouble. I was keen to solve issue during my working hours. Thanks for the comment.

1 Like

Hmm, that does sound odd… Can you make a minimal reproduceable example and toss it up on github with specific instructions that we need to follow in the terminal to create the issue so it can be traced in to? Does the same issue happen with Cachex?

I never used Cachex, and also I am using ConCache for so long, It may be happening but i never noticed or may be the issue is something else. Which I am not seeing right now. . Putting up an example, Okay, I will try and link it.

1 Like

Hi,

Unfortunately I can’t understand the problem based on this description, and I wasn’t able to reproduce it. You mention that the thing is not working from “remote console”, though I’m not sure what exactly you mean with that. To be on the safe side, I’ve tried building an OTP release, starting it, and connecting to it via the remote_console command, and that worked as expected.

One possible scenario which comes to mind is if you’re running a multinode setup, and the modification is happening on one node, while you’re querying from another node. That won’t work since ConCache is not distributed.

Another possibility is that somehow the cache gets restarted, and then primed by some older value, which is what you read.

But at this moment I can’t really say for sure. If you can make a simple reproducible project, I’d be happy to debug it.

2 Likes

Okay thank you, I found out the issue, the camera_exid was , coming as Atom instead of a string. That’s why this all was happening.

2 Likes