We can't find the internet
Attempting to reconnect
Something went wrong!
Attempting to reconnect
Analysis Summary
Ask yourself: “Did I notice what this video wanted from me, and did I decide freely to say yes?”
Worth Noting
Positive elements
- This video provides a clear, functional example of how to manage multiple cache processes and custom abstractions in Elixir using Cachex.
Be Aware
Cautionary elements
- The 'real world' example is an integrated advertisement for the creator's own platform, which uses the educational context to build trust in the software's reliability.
Influence Dimensions
How are these scored?About this analysis
Knowing about these techniques makes them visible, not powerless. The ones that work best on you are the ones that match beliefs you already hold.
This analysis is a tool for your own thinking — what you do with it is up to you.
Related content covering similar topics.
Announcing RunElixir.com
Peter Ullrich
Shared secrets management in Livebook Teams
Dashbit
IEx's Hidden Superpowers - Brett Beatty | ElixirConf US 2025
ElixirConf
Build something with Ash guided by Zach Daniel!
Peter Ullrich
Transcript
this video is about an elixir library called cachex it's a library for caching but it can also be used for storing data in memory i'm going to set up a demo elixir app and go over basic usage then i'm going to make a few useful abstractions you could add on top of it and finally i'm going to show its real world usage in the app i'm currently working on cachex is a library written by isaac whitfield as you can see it has a ton of different features but the one i'm going to focus on is time-based key expirations so let's grab the latest version and create an elixir app with the supervision tree assuming elixir is already installed in your system let's get into that folder and pull up the generated code in atom add the cachex dependency to mix.exe file and run mixdepts.get from the terminal once it's installed let's add cachex to the supervised children in the application.ex file notice that you need to provide the name for the cache in order to use it some cache in this instance now we can start the application from the terminal with iex capital s mix starting it this way lets us have a console where we can test it out cachex works like a key value store so you can type in cachex.get pass in the name of the cache some cache and then the key you want to retrieve and it returns as expected a tuple with ok nil since we didn't have anything stored yet to store something we run cachex.put some cache our key hello and the value which could be any data structure you want in this case it's a map now when we run cachex.get for that key we get our map back we can now set our key to expire in the specified time in this case we'll make it 10 seconds notice i'm using the erlang timer module to specify the expiration time now i will keep checking the key and after 10 seconds it should no longer be there and that is how cash expiration is done now let me show you a useful abstraction for this let's create a new module calling it cache1 and put it in the cache folder there's nothing special about the folder name let's take the name of the cache and make it a constant at the top of this module we'll add a get function that will take a key argument and call cachex.get with the cache name we'll do the same for put passing in key and data and adding cachex.put the same way we've done for git so now we have this module cache1 we can call to manage the cache after recompiling we can test it out by passing in a key to get function and getting back ok no tuple and then using put to actually store some data under that key and being able to get that same data back we can confirm that it works at first this abstraction does not seem to provide much value not having to pass in the cache name doesn't seem worth it what's nice though is that we can pass in the cache expiration time right into the put function in the module and not have to worry about passing it in separately once again we'll set it to 10 seconds incidentally all the timer module does is convert all values to milliseconds so you could just pass in an integer value of your expiration time in milliseconds and get the same result after recompiling we can test this out on a new key and setting the value to a string in this case and waiting 10 seconds to confirm that it expired and now it has so that is what i find useful about this abstraction but what if you wanted to have another cache with a different expiration could we just add this here in the application file as another child as you can see no no you can't in order to run multiple cachex processes we need to pass in a unique id with this supervisor spec syntax wrap in it so in order to have multiple caches we need to wrap cachex children in supervisor spec and passing a unique id to each one and after fixing this syntax issue with an extra bracket we can run the app and confirm that our cache one module still works since it needs the cache name and doesn't care about the id and it looks like it does now we can create a cache2 module for our other cache and change the expiration time to something different giving us two modules that could be used for short term and longer term cash for example i will post the code for the demo app in the description if you'd like to take a look but now i would like to show you some real world usage of this this app is called bellicose it's built on top of tradier brokerage platform to be able to easily trade vertical call and put option spreads so if this sentence makes sense to you you are able to do it so when we go to explore opportunities here one of the first things to come up is historical stock price for different intervals we have one day one month six months and so on for today's price we need the data to update frequently while historical data does not change as often for these opportunities you see here there is a lot of data that is required even before structuring all these all the active options are needed which could be up to ten thousand so it's a really good idea to cache them and not have to fetch them from the api every time so we'll just select the top opportunity and place the order back in the code these are the abstraction modules i set up for caching you can see the stock data cache and stock history cache right here this is where they are declared in the application it should all look really familiar from the demo app so back in the app the stock price is cached in stock data cache module you can see i have different get functions for sandbox versus real because sandbox prices are not real time so that is the stock data cache for stock history which is the data you get for all these different intervals i include the interval time as part of the key and you can see that anything above one day interval stays in cache for 12 hours for one day history i have logic in the code that stores it for five minutes because you want to update the graph frequently during market hours i could also have used pattern matching for one day interval without having to add conditionals elsewhere in the code but that is how i currently use cachex as i mentioned earlier there are quite a few more features in this library one that i really want to check out is cash warming which lets you pre-populate cash data reducing loading time even more hope you found this useful if you are interested in stock options trading and want to check out my app request an invite and i can set you up with a paper trading account i will leave the information in the description below thank you for watching
Video description
Basic usage and examples of cachex - an elixir library for caching and in-memory data storage Cachex library: https://github.com/whitfin/cachex Demo app: https://github.com/omgneering/hello_cachex-1 Real world app: https://bellicose.io/