Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Java by Spy Memcached to cache data     - Alien Magic: RPM and DEB Mutual Convert (Linux)

- Linux file system data file deletion problem space is not freed (Database)

- Ubuntu and Derivative Edition users install LMMS 0.4.15 (Linux)

- Eclipse 3.7.2 can not start solving under Ubuntu 14.04 (Linux)

- MySQL to recover the data through binlog (Database)

- MySQL optimization tabs (Database)

- Fedora 22 Server how to upgrade to Fedora 23 Beta Server (Linux)

- Intel Graphics Installer 1.0.3 released, support for Ubuntu (Linux)

- CentOS yum install LAMP (Server)

- CentOS x86 64bit upgrade to 2.7 Python2.6 (Linux)

- Linux Log File Browser --logrotate (Linux)

- How to use the Docker Machine cluster deployment Swarm (Server)

- Ubuntu disable graphics card (Linux)

- ActiveMQ-based shared file system HA solutions (Server)

- Security matters and practical Linux System (Linux)

- Kibana Apache Password Authentication (Server)

- How Linux Log Analysis (Linux)

- VMWare virtual machine without rebooting way to add virtual disk (Linux)

- Shell Programming points to note about the function (Programming)

- Linux System Getting Started Learning: Debian download, installation and graphical interface (Linux)

 
         
  Java by Spy Memcached to cache data
     
  Add Date : 2018-11-21      
         
         
         
  After configuring Magent + memcached, input and output of data between the obvious is through a proxy server, magent proxy server is doing is evident in memecached call java driver magent apply.

Pick SpyMemcached to cache data.

1. Define a User

Note: The type must be serialized

package memdemo;

import java.io.Serializable;

public class User implements Serializable {

/ **

    *

    * /

    private static final long serialVersionUID = 1L;

private int id;

private String name;

private int age;

public int getId () {

    return id;

}

public void setId (int id) {

    this.id = id;

}

public String getName () {

    return name;

}

public void setName (String name) {

    this.name = name;

}

public int getAge () {

    return age;

}

public void setAge (int age) {

    this.age = age;

}

@Override

public String toString () {

    return "User [id =" + id + ", name =" + name + ", age =" + age + "]";

}

}

2. Write a test class


package memdemo;

 

import java.io.IOException;

import java.net.InetSocketAddress;

 

import org.junit.Test;

 

import net.spy.memcached.MemcachedClient;

 

public class SpyMemcachedTest {

private static MemcachedClient client;

static {

    InetSocketAddress ia = new InetSocketAddress ( "127.0.0.1", 2222);

    try {

        client = new MemcachedClient (ia);

    } Catch (IOException e) {

        // TODO Auto-generated catch block

        e.printStackTrace ();

    }

}

@Test

public void add () {

    client.add ( "swder", 1, "maybo");

    System.out.println (client.get ( "swder") toString ().);

}

@Test

public void addUser () {

    User user = new User ();

    user.setAge (23);

    user.setId (1);

    user.setName ( "maybo");

    //client.add("user123 ", 0, user);

    System.out.println (client.get ( "user123") toString ().);

}

}
     
         
         
         
  More:      
 
- cat command uses the Linux redirection merge files (Linux)
- CentOS NAT iptables (Linux)
- Monitor log file (listener.log) (Database)
- Ora-00600 [fast hot Atkins soft _ that _ Oh, of course not _less_ profile] (Database)
- LaTeX Getting Started Tutorial (Linux)
- To compile and install Clang 3.5.0 in Linux CentOS (Linux)
- How to install Virtualbox 4.3.20 in Ubuntu 14.04 (Linux)
- Ubuntu 14.04 + xRDP + Xfce implement Windows Remote Desktop Connection (Linux)
- Python Multithreaded Programming (Programming)
- Django Signals from practice to source code analysis (Programming)
- DBCA Error: ORA-19809: limit exceeded for recovery files process (Database)
- Linux detection command (vmstat) (Linux)
- How to extend / remove swap partitions (Linux)
- CentOS 7 How to install MySQL Server (Database)
- A well-known but rarely used skills: object pool (Programming)
- How to use OpenVPN and PrivacyIDEA build two-factor authentication for remote access (Server)
- To create a Linux server network security (Linux)
- Network security system (Network)
- Install the latest Pinta graphics editing software on Ubuntu 14.04 (Linux)
- High-performance JavaScript DOM programming (Programming)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.