Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Follow publication

Code Smell 49 — Caches

Maximiliano Contieri
Dev Genius
Published in
2 min readDec 11, 2020

Photo by Aimee Vogelsang on Unsplash

Problems

  • Coupling
  • Testability
  • Cache invalidation.
  • Maintainability
  • Premature Optimization
  • Erratic Behavior
  • Lack of transparency
  • Non-Deterministic behavior

Solutions

  1. If you have a conclusive benchmark and are willing to pay for some coupling: Put an object in the middle.
  2. Unit test all your invalidation scenarios. Experience shows we face them in an incremental way.
  3. Look for a real world cache metaphor and model it.

Sample Code

Wrong

Right

Detection

This is a design smell.

It will be difficult to enforce by policy.

Tags

  • Premature Optimization

Conclusion

Caches should be functional and intelligent.

In this way we can manage invalidation.

General purpose caches are suitable only for low level objects like operating systems, files and streams.

We shouldn’t cache domain objects.

This page is hosted on a cached website.

Relations

More Info

There are only two hard things in Computer Science: cache invalidation and naming things.

Phil Karlton

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Published in Dev Genius

Coding, Tutorials, News, UX, UI and much more related to development

Written by Maximiliano Contieri

I’m a senior software engineer specialized in declarative designs. S.O.L.I.D. and agile methodologies fan. Maximilianocontieri.com

No responses yet

Write a response