Home Posts Tags Post Search Tag Search

Post 5

Course Work - State: Agent and ETS

Published on: 2025-04-04 Tags: elixir, Libraries, ETS, Agents
Agents are very similar to the GenServer but they don't deal  with messages, they deal with:
Agent.start_link()
Agent.update()
Agent.get()

This can send and receive data and will help you create many things that a GenServer could. 

ETS is Erland Term Storage
This is a way to create a storage system the has many of the feature that you can set in a Schema or other data types. 
:ets.new()
:ets.insert()
:ets.lookup()
are just a few of the features that we will use. The configuration of the table is where many of the key features come in. You can allow only 1 value for each key, you can set read and write access control, even order the set to name a few.

While using Agents you might run into issue with what is called a Race Condition: IE two processes try to access a database or counter at the same time and only one of the actions are shown.

That is where Caches come in. Storing the values needed into a Map you can access values as needed and store all values that are being done on the system.

We can then create a Cache with 3 different styles: ETS, Agent, and GenServer.