当前位置: 首页 > news >正文

网站怎么做直通车网站手机版排名seo

网站怎么做直通车,网站手机版排名seo,房地产开发公司网站源码,有域名在本机上做网站SpringBoot集成Memcached 1、Memcached 介绍 Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中 缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。Memcached基于一个存储…

SpringBoot集成Memcached

1、Memcached 介绍

Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载。它通过在内存中

缓存数据和对象来减少读取数据库的次数,从而提高动态、数据库驱动网站的速度。Memcached基于一个存储

键/值对的hashmap。其守护进程(daemon )是用C写的,但是客户端可以用任何语言来编写,并通过

memcached协议与守护进程通信。

因为 Spring Boot 没有针对 Memcached 提供对应的组建包,因此需要我们自己来集成。官方推出的 Java 客户端

Spymemcached 是一个比较好的选择之一。

Spymemcached 最早由 Dustin Sallings 开发,Dustin 后来和别人一起创办了 Couchbase (原NorthScale),职位

为首席架构师。2014 加入 Google。Spymemcached 是一个采用 Java 开发的异步、单线程的 Memcached 客户

端, 使用 NIO 实现。Spymemcached 是 Memcached 的一个流行的 Java client 库,性能表现出色,广泛应用于

Java + Memcached 项目中。

2、Windows下安装Memcached

官网上并未提供 Memcached 的 Windows 平台安装包,我们可以使用以下链接来下载,你需要根据自己的系统平

台及需要的版本号点击对应的链接下载即可:

  • 32位系统 1.2.5版本:http://static.runoob.com/download/memcached-1.2.5-win32-bin.zip

  • 32位系统 1.2.6版本:http://static.runoob.com/download/memcached-1.2.6-win32-bin.zip

  • 32位系统 1.4.4版本:http://static.runoob.com/download/memcached-win32-1.4.4-14.zip

  • 64位系统 1.4.4版本:http://static.runoob.com/download/memcached-win64-1.4.4-14.zip

  • 32位系统 1.4.5版本:http://static.runoob.com/download/memcached-1.4.5-x86.zip

  • 64位系统 1.4.5版本:http://static.runoob.com/download/memcached-1.4.5-amd64.zip

在 1.4.5 版本以前 memcached 可以作为一个服务安装,而在 1.4.5 及之后的版本删除了该功能。因此我们以下介

绍两个不同版本 1.4.4 及 1.4.5的不同安装方法。

2.1 memcached <1.4.5 版本安装

1、解压下载的安装包到指定目录。

2、在 1.4.5 版本以前 memcached 可以作为一个服务安装,使用管理员权限运行以下命令:

c:\memcached\memcached.exe -d install

3、然后我们可以使用以下命令来启动和关闭 memcached 服务:

c:\memcached\memcached.exe -d start
c:\memcached\memcached.exe -d stop

4、如果要修改 memcached 的配置项, 可以在命令行中执行 regedit.exe 命令打开注册表并找到

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\memcached 来进行修改。

如果要提供 memcached 使用的缓存配置可以修改 ImagePath 为:

"c:\memcached\memcached.exe" -d runservice -m 512

-m 512 意思是设置 memcached 最大的缓存配置为512M。

此外我们还可以通过使用 memcached.exe -h 命令查看更多的参数配置。

5、如果我们需要卸载 memcached ,可以使用以下命令:

c:\memcached\memcached.exe -d uninstall

2.2 memcached >= 1.4.5 版本安装

1、解压下载的安装包到指定目录。

2、在 memcached1.4.5 版本之后,memcached 不能作为服务来运行,需要使用任务计划中来开启一个普通的

进程,在 window 启动时设置 memcached自动执行。

我们使用管理员身份执行以下命令将 memcached 添加来任务计划表中:

schtasks /create /sc onstart /tn memcached /tr "'c:\memcached\memcached.exe' -m 512"

注意:-m 512 意思是设置 memcached 最大的缓存配置为512M。

注意:我们可以通过使用 c:\memcached\memcached.exe -h 命令查看更多的参数配置。

3、如果需要删除 memcached 的任务计划可以执行以下命令:

schtasks /delete /tn memcached

3、整合Memcached

3.1 pom依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.0.4.RELEASE</version><relativePath/></parent><groupId>com.example</groupId><artifactId>spring-boot-memcache-spymemcached</artifactId><version>0.0.1-SNAPSHOT</version><name>spring-boot-memcache-spymemcached</name><description>spring-boot-memcache-spymemcached</description><packaging>jar</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><java.version>1.8</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>net.spy</groupId><artifactId>spymemcached</artifactId><version>2.12.2</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

3.2 配置文件

memcache.ip=127.0.0.1
memcache.port=11211

分别配置 memcache 的 Ip 地址和 端口。

3.3 设置配置对象

创建 MemcacheSource 接收配置信息

package com.example.config;import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;@Component
@ConfigurationProperties(prefix = "memcache")
public class MemcacheSource {private String ip;private int port;public String getIp() {return ip;}public void setIp(String ip) {this.ip = ip;}public int getPort() {return port;}public void setPort(int port) {this.port = port;}
}

@ConfigurationProperties(prefix = "memcache") 的意思会以 memcache.* 为开通将对应的配置文件加载

到属性中。

3.4 启动初始化 MemcachedClient

利用 CommandLineRunner 在项目启动的时候配置好 MemcachedClient

package com.example.config;import net.spy.memcached.MemcachedClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;import javax.annotation.Resource;
import java.io.IOException;
import java.net.InetSocketAddress;@Component
public class MemcachedRunner implements CommandLineRunner {protected Logger logger = LoggerFactory.getLogger(this.getClass());@Resourceprivate MemcacheSource memcacheSource;private MemcachedClient client = null;@Overridepublic void run(String... args) throws Exception {try {client = new MemcachedClient(new InetSocketAddress(memcacheSource.getIp(), memcacheSource.getPort()));} catch (IOException e) {logger.error("inint MemcachedClient failed ", e);}}public MemcachedClient getClient() {return client;}}

3.5 启动类

package com.example;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}}

3.6 测试

package com.example;import com.example.config.MemcachedRunner;
import net.spy.memcached.MemcachedClient;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;import javax.annotation.Resource;@RunWith(SpringRunner.class)
@SpringBootTest
public class RepositoryTests {@Resourceprivate MemcachedRunner memcachedRunner;@Testpublic void testSetGet() {MemcachedClient memcachedClient = memcachedRunner.getClient();memcachedClient.set("testkey", 1000, "666666");System.out.println("***********  " + memcachedClient.get("testkey").toString());}}

使用中先测试插入一个 key 为 testkey ,1000 为过期时间单位为 毫秒,最后的 666666 为 key 对应的值。

执行测试用例 testSetGet ,控制台输出内容:

***********  666666

表明测试成功。

http://www.ds6.com.cn/news/42586.html

相关文章:

  • 网页设计导航栏尺寸百度seo排名培训优化
  • 做采购常用的几个网站郑州seo建站
  • 广州做网站最好的公司东营百度推广电话
  • 代做土木毕业设计网站互联网公司排名100强
  • 免费个人网站模版ps竞价开户推广
  • 怎么查看网站是哪个公司做的资源网
  • 衡阳网站建设步骤摘抄一篇新闻
  • 如何查看网站备案信息吗日喀则网站seo
  • 网站建设那个好天天seo伪原创工具
  • 做旅行网站浙江百度推广开户
  • 做网站一般做几个尺寸seo和sem是什么意思
  • 成都电子商务网站建设公司软文广告经典案例600
  • 王建设个人网站网站域名综合查询
  • 个人网站优秀济宁百度推广公司有几家
  • 成交型网站建设价格中央新闻联播
  • 贵州省住房和建设厅网网站关键字有哪些
  • 自己怎么做返利网站吗互联网营销师怎么报名
  • 武汉光谷做网站哪家好济南seo优化外包服务公司
  • wordpress做dropping沈阳seo团队
  • 网站建设的销售怎么做应用市场
  • 织梦做的网站怎么添加关键词百度优选官网
  • 网站主机和空间重庆专业做网站公司
  • 网站制作的论文浏览器老是出现站长工具
  • wap网站的发展微信小程序开发一个多少钱啊
  • 品牌网站建设小蝌蚪1seo排名优化排行
  • 病毒网站推广网页广告调词平台多少钱
  • 世界杯视频直播网站推荐百度推广平台登录网址
  • ssm框架做网站今天重大新闻头条新闻
  • 网站外链什么时候做企业网站建设哪家好
  • 修改wordpress登录页面优化模型的推广