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

曙光建设有限公司网站搜索引擎技术

曙光建设有限公司网站,搜索引擎技术,网站自己做还是找公司,网站建设需要什么软件有哪些Memcached是一个开源、高性能,将数据分布于内存中并使用key-value存储结构的缓存系统。它通过在内存中缓存数据来减少向数据库的频繁访问连接的次数,可以提高动态、数据库驱动之类网站的运行速度。 Memcached在使用是比较简单的,在操作上基本…

Memcached是一个开源、高性能,将数据分布于内存中并使用key-value存储结构的缓存系统。它通过在内存中缓存数据来减少向数据库的频繁访问连接的次数,可以提高动态、数据库驱动之类网站的运行速度。

Memcached在使用是比较简单的,在操作上基本就类似于操作字典结构的对象一样

1 添加依赖

这里需要添加上web、swagger和spymemcached的依赖,Swagger是为了方便接口测试。

对于spymemcached的支持,其实只要如下这个依赖包就可以了。

<!-- https://mvnrepository.com/artifact/net.spy/spymemcached -->
<dependency><groupId>net.spy</groupId><artifactId>spymemcached</artifactId><version>2.12.3</version>
</dependency>

2 添加相关配置

2.1 添加swagger 配置

添加一个swagger 配置类,在工程下新建 config 包并添加一个 SwaggerConfig 配置类,除了常规配置外,加了一个令牌属性,可以在接口调用的时候传递令牌。

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;@Configuration
@EnableSwagger2
public class SwaggerConfig {@Beanpublic Docket createRestApi(){return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select().apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();}private ApiInfo apiInfo(){return new ApiInfoBuilder().title("Swagger API Doc").description("This is a restful api document of Swagger.").version("1.0").build();}}
2.2.在配置文件添加memcache的主机端口信息

application.properties

memcache.ip=127.0.0.1
memcache.port=11211

application.yml

memcache:ip: 127.0.0.1port: 11211
2.3.添加一个MemcacheConfig配置类,读取主机端口并构造一个MemcachedClient。

MemcacheConfig.java

import java.io.IOException;
import java.net.InetSocketAddress;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import net.spy.memcached.MemcachedClient;@Configuration
public class MemcacheConfig {@Value("${memcache.ip}")private String ip;@Value("${memcache.port}")private int port;@Beanpublic MemcachedClient getClient() {MemcachedClient memcachedClient = null;try {memcachedClient  = new MemcachedClient(new InetSocketAddress(ip, port));} catch (IOException e) {e.printStackTrace();}return memcachedClient;}
}
2.4 编写业务接口

编写一个业务控制器,通过MemcachedClient实现对缓存的设置和读取。

MemcacheController.java

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import net.spy.memcached.MemcachedClient;
import net.spy.memcached.internal.OperationFuture;@RestController
public class MemcacheController {private Logger logger = LoggerFactory.getLogger(getClass());@Autowiredprivate MemcachedClient memcachedClient;@GetMapping("/info")public String memcacheGetValue() throws InterruptedException {// 取出缓存Object value = memcachedClient.get("userName");logger.info("取出缓存 "+value);return "取出的值  "+value;}@GetMapping("/save")public String saveValue(@RequestParam String userName) throws InterruptedException {// 放入缓存, 过期时间为5000,单位为毫秒OperationFuture<Boolean> flag = memcachedClient.set("userName", 5000, userName);return "保存成功";}
}

3 编译运行测试

3.1. 右键项目 -> Run as -> Maven install,开始执行Maven构建,第一次会下载Maven依赖,可能需要点时间

在这里插入图片描述

3.2. 右键文件 DemoApplication.java -> Run as -> Java Application,开始启动应用

在这里插入图片描述

3.3. 打开浏览器,访问:http://localhost:8899/swagger-ui.html,进入swagger接口文档界面。

这里的端口根据具体的项目启动来查看,我这里是 8899
在这里插入图片描述

http://www.khdw.cn/news/58308.html

相关文章:

  • 做配送平台网站多少钱百度指数是什么意思
  • 做微网站必须要有公众号吗seo内容优化是什么
  • 找人做自建房图纸去哪个网站如何进行营销推广
  • html编辑软件seo博客教程
  • 网站建设 北京百度爱采购官方网站
  • 网站做快捷方式做引流推广的平台600
  • 广州天河网站建设网站优化seo是什么意思
  • logo设计公司怎么去跟客户谈优化软件下载
  • 长沙官网网站建设微信推广朋友圈广告
  • 天津制作网站公司推荐在线培训平台有哪些
  • 网站常见 8谷歌排名优化
  • 怎样做网站备份线在科技成都网站推广公司
  • 志愿者协会网站建设武汉seo招聘信息
  • 网站建设趋势陕西网络推广公司
  • 有关商业网站的风格特征小红书关键词排名
  • 南宁伯才网络建站如何直通车关键词怎么优化
  • 建设商城网站考证培训机构报名网站
  • 商标免费查询官网做博客的seo技巧
  • 做网站的计划域名备案查询
  • 广州比较好的网站建设公司全网营销有哪些平台
  • 重庆网站推广营销代理提交链接
  • 建什么网站赚钱百度统计网站
  • 他达拉非可以长期服用吗湖南网站seo营销
  • 优质龙岗网站建设小红书关键词排名怎么做
  • 大型建设网站搜图片百度识图
  • 做外贸用什么网站好指定关键词seo报价
  • 做网站的镜像是什么意思购买域名的网站
  • 秦皇岛建设里小区网站如何进行seo
  • 黑龙江省住房和城乡建设厅seo分析报告
  • 真人做的免费视频网站关键词全网指数查询