# Module caching variable for saving database hits

**URL:** <https://forum.elixirforum.com/t/module-caching-variable-for-saving-database-hits/39369>\
**Category:** Questions\
**Tags:** ecto, phoenix\
**Created:** [May 3, 2021, 3:32am UTC](https://forum.elixirforum.com/t/module-caching-variable-for-saving-database-hits/39369 "2021-05-03T03:32:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Nicd](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/nicd/32/2357_2.png) [@Nicd](https://forum.elixirforum.com/u/Nicd)\
**Post date:** [May 3, 2021, 4:09am UTC](https://forum.elixirforum.com/t/module-caching-variable-for-saving-database-hits/39369/2 "2021-05-03T04:09:10Z")

</div>

Since Elixir is not object oriented, there are no module level variables (“properties”) that you could set like this. A process can keep state which can contain that data, and that you could accomplish with Agent or GenServer, but a single process may (or may not) become a bottleneck for the queries. Another option is to put the data in [ETS](https://erlang.org/doc/man/ets.html), perhaps using some [caching](https://hex.pm/packages?_utf8=%E2%9C%93&search=cache&sort=downloads) wrapper. There is also [persistent\_term](https://erlang.org/doc/man/persistent_term.html) which are kind of globals, but writing to them is expensive.

Personally I would think if I really need to do this, as databases should be quite good at checking a unique index already. But if I did need it and was running on a single node, I would use ETS and get the ID from there.

---

_[View the full topic](https://forum.elixirforum.com/t/module-caching-variable-for-saving-database-hits/39369)._
