Live data from Hacker News

Building a Cache in Elixir

openmymind.net

1–10 of 27 posts

Re: Building a Cache in Elixir

#2
I don't really know Elixir (though I'm interested in it), but this blog post was incredibly readable. Large font, good syntax highlighting, utilized most (but all) of the laptop screen width.

A joy to look at in a sea of hard-to-read blog posts

Re: Building a Cache in Elixir

#5

I don't really know Elixir (though I'm interested in it), but this blog post was incredibly readable. Large font, good syntax highlighting, utilized most (but all) of the laptop screen width. A joy to look at in a sea of hard-to-read blog posts

On my mobile phone the font is stupid large though, making it impossible to read.

Re: Building a Cache in Elixir

#6
One thing you can do is use :ets.slot/2 to do random probing of the cache and evict entries. The way to do so is simple, just have a process every few milliseconds check a random set of keys (say, 50 keys), and check if they expire. If >25% of keys were about to expire, repeat this process again instantly, until the % of keys expired in the batch is This is how Redis versions prior to 6.0 implemented key expiry. It's a very simple algorithm and can prove quite efficient at evicting expired keys without having to constantly scan the entire range.

Re: Building a Cache in Elixir

#7
post #5

I don't really know Elixir (though I'm interested in it), but this blog post was incredibly readable. Large font, good syntax highlighting, utilized most (but all) of the laptop screen width. A joy to look at in a sea of hard-to-read blog posts

On my mobile phone the font is stupid large though, making it impossible to read.

Good thing browser agents are just that, agents for the user. Most (if not all) have controls over the font-size, so you can make it larger/smaller at will, unless the website actively tries to defeat zooming, which this one doesn't.

For me, the font was also too large, but 0.5 seconds later, it wasn't. But no need to comment about something like this (same with the parent) as it's not actually about the article, just about something website specific.

Re: Building a Cache in Elixir

#9
post #8

"nil is greater than any integer", that was astounding. Which languages have a no-data is bigger than max_int rule?

There is a total order on (almost) all data types in the beam. This is useful for arbitrary sorting and comparison of different types.

I say almost because floats and their equivalent integer are different items but they are equal in the total order. In practice this is fine, and I have never heard of this causing a problem.

Re: Building a Cache in Elixir

#10
The purging is a scan with `next()` and a `lookup()` for each item. Since the logic is a simple `<` comparison, could this be done with a single `match_delete` instead? (Unfortunately, ETS match specifications are quite wonky, so without a lot of fiddling myself, I can't suggest exactly what the comparison logic would look like, but I know that you can express certain things like comparisons with it.) That would cut down on the back-and-forth between the elixir process and the ETS process.
Post reply on HN