Caching in ASP .NET Core: Improving Application Performance
Caching is one of the simplest techniques to significantly improve your application's performance. It's the process of temporarily storing data in a faster access location. You will typically cache the results of expensive operations or frequently accessed data.
Caching allows subsequent requests for the same data to be served from the cache instead of fetching the data from its source.
ASP .NET Core offers several types of caches, such as:
- IMemoryCache
- IDistributedCache
- HybridCache (.NET 9)
Caching improves your application's performance by reducing latency and server load while enhancing scalability and user experience.
Pros:
- Extremely fast
- Simple to implement
- No external dependencies
Cons:
- Cache data is lost if the server restarts
- Limited to the memory (RAM) of a single server
- Cache data is not shared across multiple instances of your application
How do you implement caching in .NET?
5 EF Core features you need to know 🦄🔥
1. Query spitting
- Splits JOINs into multiple queries
- Could improve query performance
- Measure performance for regressions
2. Bulk updates
- Uses ExecuteUpdate to update many entities
- Directly goes to DB, isn't part of unit of work
- Create transaction to ensure consistency
3. Raw SQL queries
- Load entities from DB using raw SQL
- Allows you to use SQL features
- SQL SELECT ... FOR UPDATE
4. Bulk deletes
- Uses ExecuteUpdate to delete many entities
- Directly goes to DB, isn't part of unit of work
- Create transaction to ensure consistency
5. Ignoring query filters
- Query filter allows you to automatically filter LINQ queries
- Ignoring the query filter can be useful sometimes
- Use this feature with caution
What is your favorite EF Core feature?
U can’t look at life in details and not ask: WAS IT DESIGNED OR COINCIDENCE ?
1. The oxygen transportation of organisms
2. The auto cleansing system of earth
3. The Milky Way galaxy, the dark hole, Cause and effect of matter and energy
Too precise for intelligent ppl to doubt.
𝗖𝗹𝗲𝗮𝗻 𝗰𝗼𝗱𝗲 𝘁𝗶𝗽: Merge nested IF statements into one condition.
This simple change can drastically improve your code readability.
But what is clean code in the first place?
Clean code is code that's:
- Easy to read
- Easy to maintain
- Easy to understand
Writing clean code is a skill. And it's a skill you can learn and improve with deliberate practice.
The general principle behind this is called the "early return" principle. Early return states that you should return from a method as soon as the conditions have been met.
In the initial example:
- Nesting increases complexity
- Nesting makes it harder to reason about code
The solution is to merge the nested IF statements into one logical expression. I achieved this using pattern matching in one example. You can also expose a method that wraps the condition and returns a boolean.
Which solution do you like better?
@SumitM_X static means something belongs to the class itself, not to individual objects created from the class
When: when all fields prop and method should be shared by all object made from the class.
Why: does every field/property needs to be unique ? If not then static does it.
My favorite job scheduling library?
It's Quartz, hands down.
I can do everything I need:
- On-demand scheduling
- Durable jobs and triggers
- Job persistence in SQL
- OpenTelemetry
I know lots of people like using Hangfire or some other popular libraries.
But Quartz has never failed me, so I don't look for alternatives.
@tarushchandra6@SumitM_X On the client side, it can be stored in the cookies yes but HTTPOnly Cookie, while on the server side it’s hashed and stored in db for validation.
of Solomon, Ecclesiastes, most of the words are written as riddles, this particular Bible verse doesn’t translate to servant and master relationship only, it could mean, the benevolent and benefactor. When you tarnish the benefactor’s image, to put is that you are a bad person.
#biblicalbriefings : Proverbs 30:10
“Do not malign a servant to his master, Lest he curse you, and you be found guilty.”
- NKJV
“Do not slander a servant to their master, or they will curse you, and you will pay for it.”
- NIV
Now because the book of Proverbs and songs …