Application of memcached in. Net

Source: Internet
Author: User

One, the installation and configuration of the service side

1) Unzip the file to C:\memcached (you can also select any location)

2) command line input ' c:\memcached\memcached.exe-d install '

3) command line input ' c:\memcached\memcached.exe-d start ', the command starts memcached, the default listener port is 11211

4) You can view its help through memcached.exe-h

Second, the client installation and reference



We have a number of options for the client-side operation server, where we choose to use the DLL. Because the way the DLL is generated faster, and avoids the cumbersome configuration file settings, it is more convenient. For Telnet commands and so on, we can use the server to check the data, see the cache hit rate, and so on.

1. About references to DLLs

After downloading the DLL, add a reference to the project

2, problems may occur

I introduced log4net and Memcached.clientlibray, the introduction, the class file also joined the using, but to generate the error, and later found to be the. NET Framework version of the issue, the version from version to. Net After the framework 4, the achievements are OK.

Third, memcached mechanism in-depth understanding

1, based on C/S architecture, simple protocol

1) C/S architecture, at this time memcached for the service side, we can use a variety of client programs to connect memcached server.

2) memcached Server client communication does not use formats such as XML, but uses simple text-line-based protocols, so that data can be saved on memcached by Telnet.

2, Libevent-based event handling

1) libevent is a package of cross-platform event processing interfaces that can be compatible with the event handling of operating systems including these operating systems: Windows/linux/bsd/solaris.

2) memcached uses libevent to handle network concurrent connections, maintaining the ability to maintain rapid response in large concurrent situations.

3, internal memory storage mode

To improve performance, the data saved in memcached is stored in Memcahced's built-in memory storage space. Since the data only exists in memory, restarting memcached and restarting the operating system will cause all data to disappear. Additionally, when the content capacity reaches the specified value, the unused cache is automatically deleted based on the LRU (Least recently used) algorithm. The memcached itself is a server designed for caching, hiding and not having too much of a permanent problem with data.

4, client-based distributed

Memcached Although it is a "distributed" cache server, the service side does not have distributed functionality. Each memcached does not communicate with each other to share information. Then, how to distribute, it is entirely dependent on the client's implementation, interested in Baidu can be the next hash algorithm.




Code experience:


Four, memcached and session

1) Different life cycle

2) The issues to be resolved differ in focus

Five, memcached and cache

Cache as. NET state management of the east, the feeling is also quite powerful: 1, cache dependency: Can rely on or file, database, combination of dependencies, and provides a data expiration notification mechanism, convenient for us to update the data in time of expiration. 2, the use of notification mechanism: Earlier, the data over the period, the use of polling mechanism, similar to the loop to see whether the data has been updated, if updated, then update the cache. But always feel the polling mechanism is very strange, for example, I burn a pot of water at home, should not be I always go to see the water is not open, but to open the water and then there is a voice told me that the water opened. Notification mechanism is this meaning, as to the principle of notification mechanism, you can go to check the Observer mode, in 23 design mode, this is still quite a lot of.

When the original use of memcached, due to the reason of the cache, naturally thought of this notification mechanism, checked, seemingly memcached is not this, to want to do an outdated update, you can only use the polling mechanism. But from Memcached's use of the scene to think, we will find that there is actually an expiration time is enough.

Six, Memcached's application scenario

1) change frequently, with unstable data, do not need real-time storage (such as user online status, online number)

2) The news of the portal website and so on, feel that the page static still cannot meet the requirements, can be put into the memcached (with jquery ajax request)

......

Seven, memcached security issues

Since memcached does not have a built-in authentication mechanism, it is possible to log in with Telnet access to the ip+ port, and then the data inside becomes the lamb to be slaughtered. To avoid being hacked, we can shut down the access port on the memcached server and allow only native programs to access it.

Eight, comparison of similar techniques

1,redis

1) Support for more value types

2) Persistent: Redis periodically writes updated data to disk or writes modifications to appended log files, and implements Master-slave (Master-Slave) synchronization on this basis

3) Support master-Slave synchronization: Data can be synchronized from the primary server to any number of slave servers, from the server can be associated with other slave server primary server. This enables Redis to perform single-layer tree replication. You can write to the data intentionally or unintentionally. Because of the full implementation of the publish/subscribe mechanism, you can subscribe to a channel and receive a complete message release record from the master server when the tree is synchronized anywhere from the database. Synchronization is helpful for the scalability and data redundancy of read operations.

2,ehcache

1) The In-process cache framework of Java, which is fast and capable, is the default Cacheprovider in Hibernate.

2) Open source Java distributed cache: primarily for general purpose caches, Java EE and lightweight containers. It features memory and disk storage, cache loaders, cache extensions, cache exception handlers, a gzip cache servlet filter, and support for rest and soap APIs.

。。。。。。。。。

The above is the content of Memcached's application in. NET, please pay attention to topic.alibabacloud.com (www.php.cn) for more relevant content.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.