Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

.net distributed Cache Memcached: how to get started to practice

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

In this issue, the editor will bring you about the .NET distributed cache Memcached from entry to practice. The article is rich in content and analyzes and describes for you from a professional point of view. I hope you can get something after reading this article.

Memcached read operation

II. Interpretation of the meaning of concept names

2.1. what is Memcached?

Memcached is a free open source, high performance, distributed in-memory key-value storage memory object caching system. It reduces the number of times to read the database by caching data and objects in memory, thus improving the speed of dynamic, database-driven websites. Memcached is based on a hashmap that stores key / value pairs. Its daemon (daemon) is written in C, but the client can write in any language and communicate with the daemon through the memcached protocol.

Some children's shoes ask how to understand distribution when they finish the course of ".NET distributed cache Redis from beginner to actual combat". So what is distributed? The simple meaning of the alphabet means that it is not local.

2.2.The advantages and disadvantages of Memcached

Advantages:

High speed, easy to operate and easy to expand

Deficiency:

1), the temporary nature of the data (the data is only stored in memory).

2) data can only be read by specifying keys, and fuzzy queries are not supported.

It is important to note that memcached uses memory to manage data, so it is volatile, and when the server restarts, or the memcached process aborts, the data is lost, so memcached cannot be used to persist data.

III. Memcached installation and configuration manual

Installation manual of Memcached on Windows system

Normally, we use linux as the production environment, but the development is still under windows, so we need the windows version. However, the official memcache website only provides the source code, so you must use a third-party compiled version of Windows.

1) installation steps of Memcache under Windows:

1. Download memcache for windows. Download address: http://downloads.northscale.com/memcached-win64-1.4.4-14.zip, extract to d:\ memcached.

2. Enter: d:\ memcached\ memcached.exe-d install in the command line state. Memcached has been installed as a windows service at this point.

3. Enter: d:\ memcached\ memcached.exe-d start at the command line to start the memcached service. Of course, you can also choose to start in the windows service.

It's that simple, the server side of a simple three-step memcache is ready.

2), set the default port and maximum memory of memcachedd. By default, the port occupied by the memcached service is 11211, and the maximum memory consumed is 64m by default.

If you need to modify these two parameters, for example, change the port to 10000 and the memory to 512.

Enter: d:\ memcached\ memcached.exe-p 10000-m 512-d start,-p represents the port to be modified, and-m represents the maximum memory occupied (in M)

3.2. Memcached configuration instruction manual

Telnet 127.0.0.1 11211 Type stats to view the current Memcached version and configuration information

Basic settings for memcached:

-Port on which p listens

-l IP address of the connection. Default is local.

-d start starts the memcached service

-d restart restarts memcached service

-d stop | shutdown shuts down the running memcached service

-d install install memcached service

-d uninstall uninstall the memcached service

-u runs as (valid only when running as root)

-m maximum memory usage, in MB. Default 64MB

-M returns an error when memory is exhausted instead of deleting an item

-c maximum number of simultaneous connections. Default is 1024.

-f block size growth factor, default is 1.25

-n minimum allocated space. Key+value+flags defaults to 48.

-h display help

Memcached Visualization client GUD Management and Monitoring tool installation Manual

TreeNMS is a Redis,Memcache visualization client tool, which is developed by JAVA to manage and maintain Redis and Memcached databases based on WEB.

TreeNMS

4. NET Memcached actual combat exercise sharing

4.1. NET Memcached Niudao pilot test

1), NET SDK Enyim.Caching training manual, read this one is enough.

Enyim.Caching training manual

2), NET SDK MemcachedClientLibrary training manual, read this article is enough. (highly recommended)

MemcachedClientLibrary training manual

3), NET SDK ServiceStack training manual, read this article is enough.

ServiceStack training manual

4.2.How does Memcached host Session in ASP.NET

MemcachedSessionProvider

Https://github.com/rohita/MemcachedSessionProvider

It is strongly recommended to use Redis as storage in actual projects!

V. after-class thinking and summary

5.1. Thinking

1) when do I choose to use Memached and Redis?

In simple Key/Value application scenarios (such as caching), Memcached has higher read and write performance, while in data persistence and data synchronization scenarios, Redis has more powerful functions and richer data types.

2), persistence of Memached and highly available variants

Memcachedb is an open source project developed by Sina based on Memcached, which makes Memcached have the ability of transaction recovery and persistence.

Repcached is a patch based on Memcached developed by Japanese, which implements the replication function of Memcached. It supports multiple Memcached to replicate each other and can solve the problem of disaster recovery.

MemcacheQ implements message queuing based on Memcached.

5.2. Summary:

Because the data exists only in memory, restarting memcached and restarting the operating system will cause all data to disappear. In addition, when the content capacity reaches the specified value, the unused cache is automatically deleted based on the LRU (Least Recently Used) algorithm. Memcached itself is a server designed for caching, so it doesn't think too much about the persistence of the data. Redis, an excellent product in NoSQL, solves the problem of data persistence better. Restarting Redis will not lead to data loss.

This is how the .NET distributed cache Memcached shared by the editor goes from beginner to practice. If you happen to have similar doubts, please refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report