Coding Global Background
Coding Global

Flyweight Pattern in Spring Boot — Render SVG Icons Efficiently (With Caching)

Archived 15 days ago
1 messages
2 members
Created a month ago
Updated 15 days ago
Open in Discord
D
direct_x_34
Script Kiddie!
What you’ll learn:
• How to stop recreating the same “heavy” objects on every request (SVG paths/templates/configs)• Flyweight split: intrinsic (shared) = icon type + SVG path, extrinsic (per request) = color + size• One endpoint, many variants: GET /api/icons?type=CART&color=%23ff0000&size=32• Flyweight Factory + ConcurrentHashMap cache to guarantee “one instance per icon type”• Verify caching: Use /api/icons/cache-size to see how many icon types are cached (e.g., 3 types → 3 flyweights)
For more details, check out the Medium link below — this article walks through the whole implementation step by step.

Link: https://sngermiyanoglu.medium.com/flyweight-pattern-in-spring-boot-render-svg-icons-efficiently-with-caching-1455370b6536