ReactJS和SpringDataRest缓存问题可能与websocket有关
ReactJS and Spring Data Rest caching issue possibly related to websockets
我似乎遇到了一个奇怪的缓存问题。
我最近搞砸了我的数据库。在我开始在我的系统中创建一些新的users
之后,我注意到出现了一个老用户。此用户尚未重新创建,并且当前不存在于数据库中。
我不确定从哪里查找缓存问题,无论是从Spring Data REST
还是从ReactJS
。有人知道这可能是从哪里来的吗?
我也有web sockets
设置。
步骤:
吹扫db:创建了新用户Web套接字进行创建然后,我使用reactjs
进行调用,从Spring Data Rest
获取一页用户,这就是奇怪的地方。
呼叫以获取用户
Headers:
Request URL:http://localhost:8081/api/users?size=4
Request Method:GET
Status Code:200 OK
Remote Address:[::1]:8081
Response Headers
view source
Content-Type:application/hal+json;charset=UTF-8
Date:Wed, 18 May 2016 22:25:29 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
Request Headers
view source
Accept:application/hal+json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Type:text/plain
Host:localhost:8081
Referer:http://localhost:8081/
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
Query String Parameters
view source
view URL encoded
size:4
BODY:
{
"_embedded" : {
"users" : [ {
"firstName" : "Aaron",
"lastName" : "Magi",
"userName" : "amagi",
"description" : "coding up a storm",
"_links" : {
"self" : {
"href" : "http://localhost:8081/api/users/1"
},
"user" : {
"href" : "http://localhost:8081/api/users/1"
}
}
}, {
"firstName" : "john",
"lastName" : "smith",
"userName" : "jsmith",
"description" : "mr smith",
"_links" : {
"self" : {
"href" : "http://localhost:8081/api/users/3"
},
"user" : {
"href" : "http://localhost:8081/api/users/3"
}
}
} ]
},
"_links" : {
"self" : {
"href" : "http://localhost:8081/api/users"
},
"profile" : {
"href" : "http://localhost:8081/api/profile/users"
}
},
"page" : {
"size" : 4,
"totalElements" : 2,
"totalPages" : 1,
"number" : 0
}
}
然后在内部调用端点以获取用户详细信息(http://localhost:8081/api/users/3)此时它返回旧的用户详细信息,而不是新的详细信息
Headers:
Request URL:http://localhost:8081/api/users/3
Request Method:GET
Status Code:304 Not Modified
Remote Address:[::1]:8081
Response Headers
view source
Date:Wed, 18 May 2016 22:25:29 GMT
ETag:"0"
Server:Apache-Coyote/1.1
Request Headers
view source
Accept:application/hal+json
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Connection:keep-alive
Content-Type:text/plain
Host:localhost:8081
If-None-Match:"0"
Referer:http://localhost:8081/
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36
BODY
{
"firstName" : "Stephen",
"lastName" : "Mann",
"userName" : "smann",
"description" : "Wizard",
"_links" : {
"self" : {
"href" : "http://localhost:8081/api/users/3"
},
"user" : {
"href" : "http://localhost:8081/api/users/3"
}
}
}
webpack.config
var path = require('path');
var node_dir = __dirname + '/node_modules';
module.exports = {
entry: './app.js',
devtool: 'sourcemaps',
cache: false,
debug: true,
resolve: {
alias: {
'stompjs': node_dir + '/stompjs/lib/stomp.js',
}
},
output: {
path: __dirname,
filename: './built/bundle.js'
},
module: {
loaders: [
{
test: path.join(__dirname, '.'),
exclude: /(node_modules)/,
loader: 'babel-loader'
// TODO remove for production
//loaders: ['react-hot','babel-loader']
}
]
}
};
Application.properties
# Keep the connection alive if idle for a long time (needed in production)
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1
# Show or not log for each sql query
spring.jpa.show-sql = true
# Hibernate ddl auto (create, create-drop, update)
spring.jpa.hibernate.ddl-auto = update
# Naming strategy
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
# Use spring.jpa.properties.* for Hibernate native properties (the prefix is
# stripped before adding them to the entity manager)
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
# Web server
spring.data.rest.base-path=/api
server.port=8081
# TODO FOR DEBUG ONLY
spring.thymeleaf.cache=false
spring.freemarker.cache=false
spring.groovy.template.cache=false
spring.velocity.cache=false
spring.mustache.cache=false
server.session.persistent=true
spring.h2.console.enabled=true
spring.resources.cache-period=0
问题
缓存发生在哪里?我可以继续创建用户,并让他们错误地显示旧数据。有没有一种方法可以正确地为您的应用程序关闭此功能?
在发布这个问题时,我注意到我在我的webpack.config.js中有cache:true。但即使将其设置为false也无法解决问题。阅读后,听起来这是缓存组件而不是数据。
感谢
事实证明,缓存是一个与IE相关的问题。在进一步阅读后,我决定我需要设置缓存控制
'Pragma': 'no-cache',
'Expires': '-1',
'cache-control': 'no-cache'
相关文章:
- chrome在WebSocket握手期间获取新错误
- ReactJS和SpringDataRest缓存问题可能与websocket有关
- 如何使用Node/Express显示有关特定错误的自定义html页面
- Node.js上的WebSocket,并在所有连接的客户端之间共享消息
- Tomcat websocket is not working
- WebSocket握手:意外的响应代码:404
- Websocket赢得't打开连接
- 如何在没有回调的情况下获取有关元素的信息
- 奇怪的日期选择器行为,与模糊有关
- Javascript connect to websocket
- 显示/隐藏有关模型更改的指令内容
- 服务器端事件+客户端事件与Websocket
- 通过html5/websocket通过wifi传输文件
- 为什么我的WebSocket客户端总是在发送消息后重新加载
- WebSocket onmessage not firing
- 有关PouchDB的复杂startkey/endkey查询未返回预期结果
- JavaScript和Java WebSocket SSL连接错误
- 需要有关修剪JavaScript的帮助
- nodejs二进制websocket mimetype处理
- WebSocket 发送有关连接的额外信息