A good Cache is critical for high performance.
6 cache strategies you need to know for that System Design interview.
Caching helps make data access faster.
To use caching effectively, you must decide how to handle reads (getting data) and writes (saving data) separately.
Here are the most popular strategies.
Cache-aside (Lazy Loading)
How it works: The application checks the cache first. If the data isn’t in the cache, it fetches it from the database, populates the cache, and returns.
Use case: Best when reads are infrequent, but data consistency is key.
Drawback: Cache miss, penalty on the initial read.
Cache-through
How it works: The cache is tightly integrated with the database. Reads and writes are managed via the cache, often with an underlying persistence mechanism.
Use case: Useful for consistent caching layer linked to the database.
Drawback: This may add complexity if the cache layer is unavailable.
Refresh-ahead
How it works: Predictively refreshes cache entries before expiration.
Use case: Suitable when cache misses are costly, and data freshness is predictable.
Drawback: May consume resources for unused data.
Write-through (Synchronous)
How it works: Writes go to the cache and the underlying database at the same time.
Use case: Ensures data consistency between the cache and database.
Drawback: Write latency is tied to both cache and database performance.
Write-behind (Asynchronous)
How it works: Writes are first made to the cache and then asynchronously persisted to the database.
Use case: Useful for optimizing write performance when data does not need to be immediately available in persistent storage.
Drawback: Possibility of data loss if the cache fails before writing to the database.
Write-around
How it works: Writes go directly to the database without immediately updating the cache. The cache gets updated on a subsequent read.
Use case: Best for use cases with infrequent reads where cache churn isn’t beneficial.
Drawback: Can lead to cache inconsistency, as it won’t always reflect the latest write until a read triggers a cache update.
Summary
Read strategies balance how and when data is loaded into the cache.
Write strategies determine how changes in data propagate between cache and persistent storage, balancing performance and consistency needs.
Save this for your next interview.
Happy cache!
@GilgameshIQ عن اي تاريخ تتحدثون
و دولة العراق عمرها ١٢٠ سنة
و دولة السعودية عمرها ١٠٠ سنة
الم تسالو نفسكم قبل الغزو البريطاني من كنتم ؟
كنتم ولايات عثمانية
لا يحق لاي عربي ان يتحدث عن التاريخ و الحضارة وهو مسجون داخل خطوط رسمته له اتفاقيات سايكس بيكو
"FastAPI is great for microservices, but not ideal for full-stack development. If you're a solo mobile developer looking to build a dashboard, Laravel is still a better choice for delivering your project. I hop FastAPI build its front-end integration like Laravel does."
@iJustAidan اذا تعمقت في تاريخ فترات الحكم الاسلامي و كيف كانت بغداد و دمشق و القاهرة و الحجاز و المغرب منارة العالم للعلم و التجارة و الاختراعات
لما سألت هذا السؤال
لكن كل ذاك التاريخ انمحى ولا توجد اي محاولة لاعادة احيائه بسبب الصراعات في الامم العربية (المدبرة)
@ibharbi هذا الراعي نفسه
لو اشتغل في الهند الي هي بلده
هل يا ترى سيجد معاملة افضل ؟
ياعمي بالهند ماكو فرق بين البشر و الحيوان ثنينهم نفس المعاملة و نفس الحياة و نفس الدرجة
وفي بعض الاحيان الحيوان يعامل افضل مثل الابقار والفئران لدرجة يعبدونهم
لكن العمل سياسي بحت لا علاقة له بالانسانية
#decorator#design_pattern involves creating a clone of your object (by creating a new class and implementing the same target object interface) and adding new behavior to it, allowing it to mimic your object with new behavior.
@MarinaMedvin It’s seems there’s someone need some likes and followers but she doesn’t has any talent or positive content 😶🌫️
I hope this pay your bills , LOZER
When you begin using PostgreSQL in your project, avoid using the @ symbol in the connection configuration. Instead, leave the password empty of the @ symbol.
@SarahAlsamarai كل عام و انتي بخير ويارب راحة البال و الصحة ذني اهم شي و فوق كلشي
واني كلش اشكرج على هاي التغريدة الصريحة اتمنى اي بنية او ولد يقرأ هاي التغريدة يخلي كل الي ذكرتيهن من اولوياته في بداية حياتة
و اتمنى ما تقسين على نفسج و ما تلزمين عداد العمرج ترة هواي ناس صعد نجمهم بعمر متاخر
Java 8 has introduced the concept of **default** methods which allow the interfaces to have methods with implementation without affecting the classes that implement the interface.