My Closet Is an LRU Cache
I have a system for hanging clothes in my closet. It's nothing fancy, and I didn't learn it from a book or a YouTube video. I just sort of stumbled into it over the years, the way you stumble into any good habit — by being mildly annoyed at the status quo for long enough that you finally do something about it.
Here's how it works. Shirts hang on the left side of the closet bar, and trousers hang on the right. Empty hangers go into the middle, between the two groups. Whenever I put away clean laundry, the clothes go onto hangers taken from the middle of the bar and placed back into the middle on the appropriate side — shirts to the left of the empty hangers, trousers to the right. When I get dressed in the morning, I choose from the ends of the bar, not the middle.
That's the entire system. No color coding, no labeling, no app.
What this does, over time, is create a natural rotation. Clean clothes enter the middle and gradually migrate toward the ends as newer clothes are placed in front of them. The stuff I wear most often stays near the center, because it keeps cycling back through the laundry and getting re-inserted. The stuff I rarely wear drifts to the outside edges, where it just sits. Once a year or so, I pull out whatever has been stuck at the ends for a while and donate it, without a moment's thought.
That last part is key. I don't have to stand in front of the closet and agonize over whether I still “need” that blue oxford shirt I bought three years ago. The system already made the decision for me. If it migrated to the end and stayed there, it means I wasn't wearing it. Case closed. Into the donation bag it goes.
The Moment I Realized What I'd Built
A while back, I was telling someone about this system, and the moment the words came out of my mouth I heard it. I knew exactly what I was describing. This wasn't just a closet-organization trick. It was a physical implementation of an LRU cache with an eviction policy.
If you've read my series on implementing a set-associative cache in C#, you already know what LRU means. For everyone else: LRU stands for Least Recently Used, and it's one of the most common cache replacement policies in computing. The idea is simple. When the cache is full and you need to add something new, you evict whatever hasn't been used for the longest time. Operating systems use it for page replacement. Databases use it for buffer pools. CDNs use it to decide what content to keep close to the edge. It's everywhere.
My closet bar is the cache. Each hanger is a cache entry. Clean laundry coming out of the dryer is new data being written. Getting dressed in the morning is a read operation. And the annual purge? That's the eviction policy firing.
The Data Structure
In my cache series, I implemented the LRU policy by sorting the keys in each set so that the most recently accessed item moves to the lowest index, pushing the least-recently used item to the highest index. My closet does the same thing, except the “lowest index” is the middle of the bar and the “highest index” is the end. Gravity and a metal rod do the bookkeeping for free.
The closet bar is actually a deque — a double-ended queue — with insertion in the middle. Items enter at the center and are consumed from the ends. In software, implementing an LRU cache usually requires a doubly-linked list combined with a hash map, so that you get O(1) lookups and O(1) reordering when an item is accessed. The closet version trades O(1) performance for something arguably better in the physical world: zero cognitive overhead. I don't have to think about it. I just put shirts on the left and grab from the end.
The partitioning is interesting, too. Shirts on the left and trousers on the right is effectively two separate caches sharing the same physical bar, each with its own eviction. In the set-associative cache I wrote in C#, I split the cache into sets, and each set managed its own entries. Same idea. Different scale.
Why It Actually Works
The reason this system is effective isn't really the rotation, although that's a nice side benefit. The real value is in the eviction. The hardest part of cleaning out a closet isn't the physical act of removing clothes. It's the decision-making. You pick up a shirt and think, “Well, I might wear this to that thing next month,” or “I paid good money for this.” That kind of thinking leads to closets full of clothes you never wear.
The closet LRU eliminates the decision. You don't have to evaluate each item on its merits. The algorithm already sorted it. If the shirt has been sitting at the end of the bar for a year, the data is clear: you don't wear it. Maybe it doesn't fit right, maybe the color isn't quite what you thought it was, maybe you just have other shirts you like better. The reason doesn't matter. The behavior speaks for itself. You just execute the eviction.
This is the same reason LRU is so popular in software. It's simple to implement, it requires minimal bookkeeping, and it produces good results in practice without needing to understand why some data is accessed more than other data. The cache doesn't care why you keep reading the same key. It just knows you do, and it keeps that data hot.
The Deeper Lesson
I think a lot about systems like this — simple processes that, once established, do the thinking for you. In the George Orwell article I wrote a while back, I talked about how stepping away from the keyboard and letting a problem settle in your mind can lead to better code. This closet system is a similar kind of idea, applied to a completely different domain. You set up the process once, and then you trust it. You don't second-guess it every morning. You just follow it.
If you're a developer, you already think this way about software systems, even if you don't realize it. You write code that makes decisions so that humans don't have to. The closet is the same thing, just implemented in wood and wire hangers instead of C# and .NET.
Next time you're standing in front of your closet wondering why you have so many clothes and nothing to wear, consider building yourself a little cache. The algorithm will sort it out.