# Using Cachex in Phoenix - working example?

**URL:** <https://forum.elixirforum.com/t/using-cachex-in-phoenix-working-example/12458>\
**Category:** Questions\
**Tags:** cache, phoenix\
**Created:** [February 12, 2018, 11:44pm UTC](https://forum.elixirforum.com/t/using-cachex-in-phoenix-working-example/12458 "2018-02-12T23:44:35Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![fireproofsocks](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/fireproofsocks/32/7669_2.png) [@fireproofsocks](https://forum.elixirforum.com/u/fireproofsocks)\
**Post date:** [February 13, 2018, 7:01pm UTC](https://forum.elixirforum.com/t/using-cachex-in-phoenix-working-example/12458/8 "2018-02-13T19:01:46Z")

</div>

Ah, ok, that makes sense. I think I should submit a PR for the docs on that.

I ended up with something like this:

```
  def get_cached_thing!(slug) do
    {status, thing} = Cachex.get(:my_cache, slug, fallback: fn(slug) ->
        Repo.get_by!(Mything, slug: slug)
    end)
    case status do
      :loaded -> thing
      :error -> "That thing does not exist"
    end
  end

```

That works, but I’m open to any comments/improvements/suggestions. Not sure how idiomatic that solution is. Thanks!

---

_[View the full topic](https://forum.elixirforum.com/t/using-cachex-in-phoenix-working-example/12458)._
