Telegram Group & Telegram Channel
إزاي تنفذ الـ Caching في Node.js؟ 🤔
.
.
لو أنت شغال بـ Node.js، فـ أكيد قابلت في يوم مشكلة إن الـ API عندك بيبقى بطيء بسبب requests كتير أو عمليات تقيلة زي queries على database، وبدأت تفكر:
"ليه كل مرة أجيب نفس الداتا؟ طب مفيش حل أسرع؟"

الإجابة هي: Caching.

وده اللي هنتكلم عنه اليوم بالتفصيل....

[ كل الأكواد هتلاقيها في التعليقات تحت الرسالة ]

———

🎯 إيه هو الـ Caching؟


ببساطة، هو إنك تحفظ نسخة من الداتا مؤقتًا في مكان تاني (بيكون أسرع من المصدر الأساسي زي الـ DB)، علشان لما تيجي تطلب نفس الحاجة تاني، ما تروح تجيبها من الأول، لا، ترد بسرعة من الـ cache.

وده بيفرق جامد جدًا في السرعة، والأداء، والحمل على السيرفر.

———

إزاي تعمل الـ Caching في Node.js؟


1. الـ In-Memory Caching (باستخدام node-cache أو lru-cache)

لو عندك داتا مش كبيرة ومش محتاج تشاركها بين أكتر من instance، فـ in-memory caching بيكون حل سريع وسهل.

📌 مناسب لحالات زي الداتا القليلة، أو عمليات حسابية تقيلة، بس خلي بالك إنه volatile، يعني لو السيرفر عمل restart، كل حاجة بتروح.

———

2. الـ Redis Caching (الحل الأقوى والأشهر)

لو بتدور على Cache centralized وسريع وتقدر تشارك الداتا بين أكتر من instance، يبقى Redis هو الأفضل هنا.

🎯 الـ Redis سريع جدًا، وبيستخدم في مشاريع كبيرة زي Twitter و GitHub. وكمان تقدر تتحكم في TTL، وتعمل invalidation، وتخزن أكتر من نوع داتا.

———

3. الـ Caching Responses مباشرة (مثلًا في GraphQL أو REST)

لو شغال مثلاً بـ Apollo Server في GraphQL، تقدر تستخدم built-in caching

أو حتى لو شغال REST تقدر تستخدم middlewares زي apicache أو express-cache-controller.

———

🤔 إمتى تستخدم الـ Caching؟


- لما تكون بتكرر نفس الـ requests بكميات كبيرة.
- لما الداتا تكون مش بتتغير كتير.
- لو الـ DB عندك بطيئة أو بتاخد وقت في المعالجة.
- لو عايز تقلل الترافيك على الـ backend.

———

⚠️ خلي بالك:


لازم تعمل Cache Invalidation كويس، علشان ما ترجع داتا قديمة بعد التحديث.

بلاش تستخدم الـ Caching لأي داتا حساسة أو شخصية (privacy first).

خليك دايمًا عارف إمتى تعمل Cache، وإمتى لا... مش كل حاجة محتاجة تتخزن.

———

وفقكم الله لكل خير 🌿



tg-me.com/the_developer_guide/5305
Create:
Last Update:

إزاي تنفذ الـ Caching في Node.js؟ 🤔
.
.
لو أنت شغال بـ Node.js، فـ أكيد قابلت في يوم مشكلة إن الـ API عندك بيبقى بطيء بسبب requests كتير أو عمليات تقيلة زي queries على database، وبدأت تفكر:
"ليه كل مرة أجيب نفس الداتا؟ طب مفيش حل أسرع؟"

الإجابة هي: Caching.

وده اللي هنتكلم عنه اليوم بالتفصيل....

[ كل الأكواد هتلاقيها في التعليقات تحت الرسالة ]

———

🎯 إيه هو الـ Caching؟


ببساطة، هو إنك تحفظ نسخة من الداتا مؤقتًا في مكان تاني (بيكون أسرع من المصدر الأساسي زي الـ DB)، علشان لما تيجي تطلب نفس الحاجة تاني، ما تروح تجيبها من الأول، لا، ترد بسرعة من الـ cache.

وده بيفرق جامد جدًا في السرعة، والأداء، والحمل على السيرفر.

———

إزاي تعمل الـ Caching في Node.js؟


1. الـ In-Memory Caching (باستخدام node-cache أو lru-cache)

لو عندك داتا مش كبيرة ومش محتاج تشاركها بين أكتر من instance، فـ in-memory caching بيكون حل سريع وسهل.

📌 مناسب لحالات زي الداتا القليلة، أو عمليات حسابية تقيلة، بس خلي بالك إنه volatile، يعني لو السيرفر عمل restart، كل حاجة بتروح.

———

2. الـ Redis Caching (الحل الأقوى والأشهر)

لو بتدور على Cache centralized وسريع وتقدر تشارك الداتا بين أكتر من instance، يبقى Redis هو الأفضل هنا.

🎯 الـ Redis سريع جدًا، وبيستخدم في مشاريع كبيرة زي Twitter و GitHub. وكمان تقدر تتحكم في TTL، وتعمل invalidation، وتخزن أكتر من نوع داتا.

———

3. الـ Caching Responses مباشرة (مثلًا في GraphQL أو REST)

لو شغال مثلاً بـ Apollo Server في GraphQL، تقدر تستخدم built-in caching

أو حتى لو شغال REST تقدر تستخدم middlewares زي apicache أو express-cache-controller.

———

🤔 إمتى تستخدم الـ Caching؟


- لما تكون بتكرر نفس الـ requests بكميات كبيرة.
- لما الداتا تكون مش بتتغير كتير.
- لو الـ DB عندك بطيئة أو بتاخد وقت في المعالجة.
- لو عايز تقلل الترافيك على الـ backend.

———

⚠️ خلي بالك:


لازم تعمل Cache Invalidation كويس، علشان ما ترجع داتا قديمة بعد التحديث.

بلاش تستخدم الـ Caching لأي داتا حساسة أو شخصية (privacy first).

خليك دايمًا عارف إمتى تعمل Cache، وإمتى لا... مش كل حاجة محتاجة تتخزن.

———

وفقكم الله لكل خير 🌿

BY DevGuide 🇵🇸


Warning: Undefined variable $i in /var/www/tg-me/post.php on line 283

Share with your friend now:
tg-me.com/the_developer_guide/5305

View MORE
Open in Telegram


DevGuide 🇵🇸 Telegram | DID YOU KNOW?

Date: |

Should I buy bitcoin?

“To the extent it is used I fear it’s often for illicit finance. It’s an extremely inefficient way of conducting transactions, and the amount of energy that’s consumed in processing those transactions is staggering,” the former Fed chairwoman said. Yellen’s comments have been cited as a reason for bitcoin’s recent losses. However, Yellen’s assessment of bitcoin as a inefficient medium of exchange is an important point and one that has already been raised in the past by bitcoin bulls. Using a volatile asset in exchange for goods and services makes little sense if the asset can tumble 10% in a day, or surge 80% over the course of a two months as bitcoin has done in 2021, critics argue. To put a finer point on it, over the past 12 months bitcoin has registered 8 corrections, defined as a decline from a recent peak of at least 10% but not more than 20%, and two bear markets, which are defined as falls of 20% or more, according to Dow Jones Market Data.

How Does Bitcoin Work?

Bitcoin is built on a distributed digital record called a blockchain. As the name implies, blockchain is a linked body of data, made up of units called blocks that contain information about each and every transaction, including date and time, total value, buyer and seller, and a unique identifying code for each exchange. Entries are strung together in chronological order, creating a digital chain of blocks. “Once a block is added to the blockchain, it becomes accessible to anyone who wishes to view it, acting as a public ledger of cryptocurrency transactions,” says Stacey Harris, consultant for Pelicoin, a network of cryptocurrency ATMs. Blockchain is decentralized, which means it’s not controlled by any one organization. “It’s like a Google Doc that anyone can work on,” says Buchi Okoro, CEO and co-founder of African cryptocurrency exchange Quidax. “Nobody owns it, but anyone who has a link can contribute to it. And as different people update it, your copy also gets updated.”

DevGuide 🇵🇸 from it


Telegram DevGuide 🇵🇸
FROM USA