浏览器缓存与nginx缓存

浏览器缓存

优点:使用有效缓存时,没有网络消耗,速度快;即使有网络消耗,但对失效缓存使用304响应做到网络消耗最小化

缺点:仅提升一个用户的体验

nginx 缓存

优点:提升所有用户体验,相比浏览器缓存,有效降低上游服务的负载,通过304响应减少nginx与上游服务间的流量消耗

缺点:用户仍然保持网络消耗

同时使用浏览器与nginx缓存

Etag 头部

ETagHTTP 响应头是资源的特定版本的标识符。可以是缓存更高效,并节省带宽,因为如果内容没有改变。web服务不需要发送完整的响应。如果内容发生变化,使用ETag有助于防止资源的同时更新互换覆盖;如果给定URL中的资源更改,则一定要生成新的Etag值。因此Etge类似于指纹,也可能被某些服务器用于追踪。比较etags能快速确定此资源是否变化,但也可能被追踪服务器永久保存
W/可选
 ‘W/’(大小写敏感)表示使用弱验证器,弱验证器很容易生成不利于比较,强验证器是比较的理想选择,但很难生成,相同资源的两个弱Etag值可能语义相同,但不是每个字节都相同
 
etag 指令
Syntax: etag on | off;
Default: etag on;
Context: http, server, location

  生成规则

ngx_sprintf(etag->value.data, "\"%xT-%xO\"",
r->headers_out.last_modified_time,
r->headers_out.content_length_n)

  If-None-Match

If-Modified-Since 头部

not_modified过滤模块

expires 指令
Syntax: expires [modified] time;
expires epoch | max | off; #指的一个绝对时间,表示缓存在这段时间内一直有效
Default: expires off;
Context: http, server, location, if in location

 

配置

[root@python vhast]# cat cache.conf
server {
server_name cache.com;
error_log logs/cacgeee.log;
access_log logs/cache.log main;
root html/;
location /{
etag on; 启用
expires 1h;缓存1小时
#expires -1h;
#expires @20h30m;
#if_modified_since off;
#proxy_cache two;
#proxy_cache_valid 100 10m;
#add_header X-Cache-Status $upstream_cache_status;
#proxy_cache_use_stale error timeout updating;
#proxy_cache_revalidate on;
#proxy_cache_background_update on;
#proxy_hide_header Set-Cookie;
#proxy_ignore_headers Set-Cookie;
#proxy_force_ranges on;
#proxy_pass http://127.0.0.1:8012;
}
}

  测试

[root@python vhast]# date -u
2019年 07月 17日 星期三 16:12:16 UTC
[root@python vhast]# curl cache.com/ -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 16:12:19 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
Connection: keep-alive
ETag: "5d262d06-264"
Expires: Wed, 17 Jul 2019 17:12:19 GMT
Cache-Control: max-age=3600
Accept-Ranges: bytes

    配置

[root@python vhast]# cat cache.conf
server {
server_name cache.com;
error_log logs/cacgeee.log;
access_log logs/cache.log main;
root html/;
location /{
etag on;
#expires 1h;
expires -1h; #设置前一小时失效
#expires @20h30m;
#if_modified_since off;
#proxy_cache two;
#proxy_cache_valid 100 10m;
#add_header X-Cache-Status $upstream_cache_status;
#proxy_cache_use_stale error timeout updating;
#proxy_cache_revalidate on;
#proxy_cache_background_update on;
#proxy_hide_header Set-Cookie;
#proxy_ignore_headers Set-Cookie;
#proxy_force_ranges on;
#proxy_pass http://127.0.0.1:8012;
}
}

  测试

[root@python vhast]# date -u
2019年 07月 17日 星期三 16:16:37 UTC
[root@python vhast]# curl cache.com/ -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 16:16:48 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
Connection: keep-alive
ETag: "5d262d06-264"
Expires: Wed, 17 Jul 2019 15:16:48 GMT
Cache-Control: no-cache #缓存失效
Accept-Ranges: bytes

  配置指的浏览器缓存到指定的时间

[root@python vhast]# cat cache.conf
server {
server_name cache.com;
error_log logs/cacgeee.log;
access_log logs/cache.log main;
root html/;
location /{
etag on;
#expires 1h;
#expires -1h;
expires @20h30m; 缓存到最近的20点半
#if_modified_since off;
#proxy_cache two;
#proxy_cache_valid 100 10m;
#add_header X-Cache-Status $upstream_cache_status;
#proxy_cache_use_stale error timeout updating;
#proxy_cache_revalidate on;
#proxy_cache_background_update on;
#proxy_hide_header Set-Cookie;
#proxy_ignore_headers Set-Cookie;
#proxy_force_ranges on;
#proxy_pass http://127.0.0.1:8012;
}
}

  测试

[root@python vhast]# date -u
2019年 07月 17日 星期三 16:18:54 UTC
[root@python vhast]# curl cache.com/ -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 16:18:57 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
Connection: keep-alive
ETag: "5d262d06-264"
Expires: Thu, 18 Jul 2019 12:30:00 GMT
Cache-Control: max-age=72663
Accept-Ranges: bytes

  

not_modified 过滤模块

not_modified 指令
Syntax: if_modified_since off | exact | before;
Default: if_modified_since exact;
Context: http, server, location

  

测试

  

[root@python vhast]# curl cache.com/ -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 16:47:10 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
Connection: keep-alive
ETag: "5d262d06-264"
Expires: Thu, 18 Jul 2019 12:30:00 GMT
Cache-Control: max-age=70970
Accept-Ranges: bytes [root@python vhast]# curl -H 'If_Modified_Since: Wed, 10 Jul 2019 18:23:02 GMT' -H 'If-None-Match: "5d262d06-264"' cache.com/ -I
HTTP/1.1 304 Not Modified#命中缓存
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 16:47:22 GMT
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
Connection: keep-alive
ETag: "5d262d06-264"
Expires: Thu, 18 Jul 2019 12:30:00 GMT
Cache-Control: max-age=70958 [root@python vhast]# curl -H 'If_Modified_Since: Wed, 10 Jul 2019 18:23:02 GMT' -H 'If-None-Match: "5d262d06-267"' cache.com/ -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 16:48:12 GMT
Content-Type: text/html
Content-Length: 612
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
Connection: keep-alive
ETag: "5d262d06-264"
Expires: Thu, 18 Jul 2019 12:30:00 GMT
Cache-Control: max-age=70908
Accept-Ranges: bytes

  

If-Match 

If-Unmodified-Since

nginx 缓存:定义存放缓存的载体
Syntax: proxy_cache zone | off;
Default: proxy_cache off;
Context: http, server, location Syntax:
proxy_cache_path path [levels=levels] [use_temp_path=on|off]
keys_zone=name:size [inactive=time] [max_size=size] [manager_files=number]
[manager_sleep=time] [manager_threshold=time] [loader_files=number]
[loader_sleep=time] [loader_threshold=time] [purger=on|off] [purger_files=number]
[purger_sleep=time] [purger_threshold=time];
Default: —
Context: http

  

proxy_cache_path 指令

缓存关键字

Syntax: proxy_cache_key string;
Default: proxy_cache_key $scheme$proxy_host$request_uri;
Context: http, server, location

缓存什么样的响应

Syntax: proxy_cache_valid [code ...] time;
Default: —
Context: http, server, location

  

那些内容不使用缓存

参数为真时响应不存入缓存

Syntax: proxy_no_cache string ...;
Default: —
Context: http, server, location

  参数为真时,不使用缓存内容

Syntax: proxy_cache_bypass string ...;
Default: —
Context: http, server, location

  变更HEAD方法

Syntax: proxy_cache_convert_head on | off;
Default: proxy_cache_convert_head on;
Context: http, server, location

  upstream_cache_status变量

upstream_cache_status
MISS:未命中缓存;  HIT:命中缓存; EXPIRED:缓存已过期;STALE:命中陈旧的缓存;UPDATING:内容陈旧,正在更新;REVALIDATED:nginx验证陈旧的内容依然有效 ;BYPASS:内容是从原始服务器获得

缓存流程

对那个method方法使用缓存返回响应

Syntax: proxy_cache_methods GET | HEAD | POST ...;
Default: proxy_cache_methods GET HEAD;
Context: http, server, location 

 配置

server {
listen 8012;
default_type text/plain;
root html;
location /{
#add_header X-Accel-Limit-Rate 10; }
location /test { return 200 '8012 server response.
uri: $uri
method: $request_method
requset: $request
http_name: $http_name
\n';
}
} [root@python vhast]# cat cache.conf
proxy_cache_path /data/web/cache levels=2:2 keys_zone=two:10m loader_threshold=300 loader_files=200 max_size=200m inactive=1m;
server {
server_name cache.com;
error_log logs/cacgeee.log;
access_log logs/cache.log main;
root html/;
location /{
etag on;
#expires 1h;
#expires -1h;
#expires @20h30m;
#if_modified_since off;
proxy_cache two;
proxy_cache_valid 200 1m;
add_header X-Cache-Status $upstream_cache_status;
#proxy_cache_use_stale error timeout updating;
#proxy_cache_revalidate on;
#proxy_cache_background_update on;
#proxy_hide_header Set-Cookie;
#proxy_ignore_headers Set-Cookie;
#proxy_force_ranges on;
proxy_pass http://127.0.0.1:8012;
}
}

  测试

[root@python vhast]# curl  cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:23:40 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
X-Cache-Status: MISS 第一次
Accept-Ranges: bytes [root@python vhast]# curl cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:23:44 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
X-Cache-Status: HIT 第二次
Accept-Ranges: bytes

  

  

X-Accel-Expires头部

配置

server {
listen 8012;
default_type text/plain;
#client_body_in_single_buffer on;
#add_header Cache_Control 'max-age=3,stale-while-revalidate=3';
#add_header Vary *;
add_header X-Accel-Expires 3; #定义代理服务器缓存为3秒
root html;
location /{
#add_header X-Accel-Limit-Rate 10; }
location /test { return 200 '8012 server response.
uri: $uri
method: $request_method
requset: $request
http_name: $http_name
\n';
}
}

  测试

[root@python vhast]# curl  cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:35:20 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
X-Cache-Status: EXPIRED
Accept-Ranges: bytes [root@python vhast]# curl cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:35:21 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
X-Cache-Status: HIT
Accept-Ranges: bytes [root@python vhast]# curl cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:35:22 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
X-Cache-Status: HIT
Accept-Ranges: bytes [root@python vhast]# curl cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:35:23 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
X-Cache-Status: HIT
Accept-Ranges: bytes [root@python vhast]# curl cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:35:25 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
X-Cache-Status: EXPIRED
Accept-Ranges: bytes

  

vary 头部

配置

server {
listen 8012;
default_type text/plain;
#client_body_in_single_buffer on;
#add_header Cache_Control 'max-age=3,stale-while-revalidate=3';
add_header Vary *; #配置代理不缓存
add_header X-Accel-Expires 3; #定义上游服务器缓存为3
root html;
location /{
#add_header X-Accel-Limit-Rate 10; }
location /test { return 200 '8012 server response.
uri: $uri
method: $request_method
requset: $request
http_name: $http_name
\n';
}
}

  测试

[root@python vhast]# curl  cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:38:23 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
Vary: *
Accept-Ranges: bytes
X-Cache-Status: MISS [root@python vhast]# curl cache.com/a.txt -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 17:38:23 GMT
Content-Type: text/plain
Content-Length: 23
Connection: keep-alive
Last-Modified: Fri, 12 Jul 2019 14:07:41 GMT
ETag: "5d28942d-17"
Vary: *
Accept-Ranges: bytes
X-Cache-Status: MISS

  

Set-Cookie头部

Set-Cookie: <cookie-name>=<cookie-value>
Set-Cookie: <cookie-name>=<cookie-value>; Expires=<date>
Set-Cookie: <cookie-name>=<cookie-value>; Max-Age=<non-zero-digit>
Set-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>
Set-Cookie: <cookie-name>=<cookie-value>; Path=<path-value>
Set-Cookie: <cookie-name>=<cookie-value>; Secure
Set-Cookie: <cookie-name>=<cookie-value>; HttpOnly
Set-Cookie: <cookie-name>=<cookie-value>; SameSite=Strict
Set-Cookie: <cookie-name>=<cookie-value>; SameSite=Lax
Set-Cookie: <cookie-name>=<cookie-value>; Domain=<domain-value>; Secure; HttpOnly

  缓存流程:接收上游的响应

合并回源请求-减少峰值流量下的压力

Syntax: proxy_cache_lock on | off;
Default: proxy_cache_lock off;
Context: http, server, location 同一时间,仅第一个请求发往上游,其他请求等待第一个响应返回或者超时候,使用缓存响应客户端
Syntax: proxy_cache_lock_timeout time;
Default: proxy_cache_lock_timeout 5s;
Context: http, server, location
等待第一个请求返回响应的最大时间,到达后直接向上游发送请求,但不缓存响应
Syntax: proxy_cache_lock_age time;
Default: proxy_cache_lock_age 5s;
Context: http, server, location
上一个请求返回响应的超时时间,到达后再放行一个请求发送向上游

  减少回源请求试图stale陈旧的缓存

Syntax: proxy_cache_use_stale error | timeout | invalid_header |
updating | http_500 | http_502 | http_503 | http_504 |
http_403 | http_404 | http_429 | off ...;
Default: proxy_cache_use_stale off;
Context: http, server, location Syntax: proxy_cache_background_update on | off;
Default: proxy_cache_background_update off;
Context: http, server, location

  proxy_cache_use_stale指定陈旧缓存的用法

缓存有问题时的响应

Syntax: proxy_cache_background_update on | off;
Default: proxy_cache_background_update off;
Context: http, server, location

  当使用proxy_cache_use_stale允许使用过期响应时,将同步生成一个子请求,通过访问上游服务更新过期的缓存

Syntax: proxy_cache_revalidate on | off;
Default: proxy_cache_revalidate off;
Context: http, server, location

  更新缓存时,使用If-Modified-Since和If-None-Match作为请求头部,预期内容未发生变更时通过304来减少传输的内容

及时清除缓存

模块第三方模块ngx_cache_purge 地址 https://github.com/FRiCKLE/ngx_cache_purge

使用--add-module=指令编译添加到nginx中

功能:接收到指定HTTP请求后立刻清除缓存

•syntax: proxy_cache_purge on|off|<method> [from all|<ip> [.. <ip>]]
•default: none
•context: http, server, location •syntax: proxy_cache_purge zone_name key
•default: none
•context: location

  编译进第三方模块

git clone https://github.com/FRiCKLE/ngx_cache_purge.git
cd nginx-1.15.9/
./configure --prefix=/data/web --sbin-path=/usr/bin --user=nginx --group=nginx --with-http_stub_status_module --with-http_auth_request_module --with-http_sub_module --add-module=/root/nginx-http-concat --with-http_addition_module --with-http_secure_link_module --with-http_geoip_module --with-http_ssl_module --add-module=/root/ngx_cache_purge
make
mv /usr/bin/nginx{,.01.18.15.41}
cp objs/nginx /usr/bin/

  配置

[root@python vhast]# cat cache.conf
proxy_cache_path /data/web/cache levels=2:2 keys_zone=two:10m loader_threshold=300 loader_files=200 max_size=200m inactive=1m;
server {
server_name cache.com;
error_log logs/cacgeee.log;
access_log logs/cache.log main;
root html/;
location ~/purge(/.*) {
proxy_cache_purge two $scheme$1; 匹配上的时候,就清空这个缓存
}
location /{
etag on;
#expires 1h;
#expires -1h;
#expires @20h30m;
#if_modified_since off;
proxy_cache two;
proxy_cache_valid 200 1m;
add_header X-Cache-Status $upstream_cache_status;
#proxy_cache_use_stale error timeout updating;
#proxy_cache_revalidate on;
#proxy_cache_background_update on;
#proxy_hide_header Set-Cookie;
#proxy_ignore_headers Set-Cookie;
#proxy_force_ranges on;
proxy_cache_key $scheme$uri;
proxy_pass http://127.0.0.1:8012;
}
}

  测试

[root@python vhast]# curl  cache.com/index.html -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 20:16:30 GMT
Content-Type: text/html
Content-Length: 612
Connection: keep-alive
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
ETag: "5d262d06-264"
X-Cache-Status: MISS #未命中
Accept-Ranges: bytes [root@python vhast]# curl cache.com/index.html -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 20:16:31 GMT
Content-Type: text/html
Content-Length: 612
Connection: keep-alive
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
ETag: "5d262d06-264"
X-Cache-Status: HIT #命中
Accept-Ranges: bytes [root@python vhast]# curl cache.com/index.html -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 20:16:35 GMT
Content-Type: text/html
Content-Length: 612
Connection: keep-alive
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
ETag: "5d262d06-264"
X-Cache-Status: HIT #命中
Accept-Ranges: bytes [root@python vhast]# curl cache.com/purge/index.html -I #清除缓存
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 20:16:40 GMT
Content-Type: text/html
Content-Length: 270
Connection: keep-alive [root@python vhast]# curl cache.com/index.html -I
HTTP/1.1 200 OK
Server: nginx/1.15.9
Date: Wed, 17 Jul 2019 20:16:42 GMT
Content-Type: text/html
Content-Length: 612
Connection: keep-alive
Last-Modified: Wed, 10 Jul 2019 18:23:02 GMT
ETag: "5d262d06-264"
X-Cache-Status: MISS #未命中
Accept-Ranges: bytes

  

七层反向代理对照:构造请求内容

七层反向代理对照:建立连接并发送请求

七层反向代理:接收上游响应

转发响应

七层代理SSL

缓存类的指令

七层反代独有配置

nginx 缓存的更多相关文章

  1. ASP.NET Core 缓存技术 及 Nginx 缓存配置

    前言 在Asp.Net Core Nginx部署一文中,主要是讲述的如何利用Nginx来实现应用程序的部署,使用Nginx来部署主要有两大好处,第一是利用Nginx的负载均衡功能,第二是使用Nginx ...

  2. nginx缓存设置proxy_cache

    http://www.cnblogs.com/dudu/p/4597351.html http块: proxy_cache_path /tmp/cache levels=1:2 keys_zone=n ...

  3. nginx缓存配置的操作记录梳理

    web缓存位于内容源Web服务器和客户端之间,当用户访问一个URL时,Web缓存服务器会去后端Web源服务器取回要输出的内容,然后,当下一个请求到来时,如果访问的是相同的URL,Web缓存服务器直接输 ...

  4. nginx 缓存机制

    nginx 缓存机制   Nginx缓存的基本思路 利用请求的局部性原理,将请求过的内容在本地建立一个副本,下次访问时不再连接到后端服务器,直接响应本地内容 Nginx服务器启动后,会对本地磁盘上的缓 ...

  5. Nginx 缓存参数

    看看这下面两个指令参数: ----------------------------------------------------------------- proxy_cache_path  /ho ...

  6. 分布式Nginx缓存清理(PHP的socket编程)

    最近,公司要使用康乐的几台自建CDN换成Nginx,在缓存配置上不会有很多的问题,纠结的问题是:Nginx的如何批量进行缓存清理 我们都知道Nginx提供了一个第三方的模块"nginx ng ...

  7. nginx缓存优先级(缓存问题者必看)

    接触nginx的兄弟或多或少都有遇到缓存问题,要么是nginx为什么不缓存,要么就是nginx缓存很快就失效等等问题,在网上找了一遍nginx缓存优先级的文章,大家可以参考下. 架构图client端  ...

  8. Nginx实现负载均衡&Nginx缓存功能

    一.Nginx是什么 Nginx (engine x) 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambl ...

  9. 使用nginx缓存服务器上的静态文件

    一.nginx缓存的优点 如图所示,nginx缓存,可以在一定程度上,减少源服务器的处理请求压力. 因为静态文件(比如css,js, 图片)中,很多都是不经常更新的.nginx使用proxy_cach ...

  10. nginx缓存设置(expires)

    一.expires功能说明 nginx缓存的设置可以提高网站性能,对于网站的图片,尤其是新闻网站,图片一旦发布,改动的可能是非常小的,为了减小对服务器请求的压力,提高用户浏览速度,我们可以通过设置ng ...

随机推荐

  1. [NLP]Transformer模型解析

    简介[2] Attention Is All You Need是2017年google提出来的一篇论文,论文里提出了一个新的模型,叫Transformer,这个结构广泛应用于NLP各大领域,是目前比较 ...

  2. 初学mysql数据库

    package com.conn; import java.sql.Connection; import java.sql.DriverManager; public class Conn { pub ...

  3. HahMap相关问题

    概述 文章对HashMap的部分细节进行介绍,JDK1.7之前有可能出现环形表的问题,而1.7之后进行了改进,文章对环形表现象的出现进行了解析,然后对HashMap注意的几个问题进行了解答. Hash ...

  4. 设备驱动基础学习--platform driver简单实现

    platform是一条虚拟的总线.设备用platform_device表示,驱动用platform_driver进行注册,Linux platform driver机制和传统的device drive ...

  5. Django报错 The serializer field might be named incorrectly and not match any Got AttributeError when attempting to get a value for field `author_for` on serializer `KnownledgeBaseListSerializer`

    1.问题描述,在设置,model部分字段的serialier时,出现如下报错 字段如下: # 知识库List class KnownledgeBaseListSerializer(serializer ...

  6. OGG在windows环境下字符集的配置

    windows环境下不配置字符集(默认使用windows自己的字符集),从linux等系统同步过来的表中如果含有中文字符列将显示为乱码,被ogg误认为虚拟列,从而导致进程abend. 设置ogg进程在 ...

  7. JVM 初始

    我们刚学习java的时候,从来没有想过new一个对象后,需要我们手动去管理过他的内存空间释放,因为我们知道java有GC垃圾回收器这哥们的存在,他会帮我们处理好一切,这就好比我是皇帝,我想在哪建个行宫 ...

  8. Yii2.0 引入外部js css

    <script src="<?= Yii::$app->request->baseUrl . '/js/jquery-2.1.1.min.js'?>" ...

  9. HTML-移动端-rem px vw vh 的转换

    vw/vh rem px 三者的转换(快速入门移动端页面编写) 1:三种单位的转换 2:如何适配移动端的不同设备 前提知识: 手机端的长宽是实际设计过程中的两倍 比如手机端是 750 * 1200 那 ...

  10. SpringCloud全家桶学习之分布式配置中心----Config(七)

    一.概述 (1)背景 微服务意味着将单体应用中的业务拆分成一个个子服务,每个服务的粒度相对较小,因此系统中出现大量的服务.由于每个服务都需要配置必要的配置信息才能运行,所以一套集中式的.动态的配置管理 ...