缓存
缓存功能提高查询效率,减少数据库压力。当缓存中有结果时将不再查询数据库。
用途用于查询,适合查询较多的场合。
注意insert、update、delete都会使缓存失效。或超时失效
一级缓存作用缓存是一个map。
SqlSession会将statementId,params,rowBounds作为key,结果为value。
执行查询时会先判断cache总是否有本次的key。存在且未超时,直接返回value;若不存在,则将本次key和value存入cache,并返回value
作用域SqlSession(实际由Executor存储并管理),不能跨Session共享
生命周期创建SqlSession对象时,会创建缓存Executor调用clearCache或增删改时,会清空缓存SqlSession关闭时,缓存Executor也关闭
失效调用clearCache清空一级缓存
脏数据多个session之间缓存可能不同,形成脏数据
可以设置一级缓存为statement级别,每次查询都将清除一级缓存
设置MyBatis默认开启一级缓存,且无法关闭
使用默认已经使用
二级缓存作用跨session共享 ...
nginx代理后仍为原路径
复现使用nginx代理127.0.0.1:8000/bbs转至xxx.com,主页正常,但所有其他链接均为原路径,即其他路径仍为127***,并不是xxx.com/***。
解决方法在配置文件中添加请求头
1proxy_set_header Host $http_host;
using System.Text.Json to serialize and deserialize object
Serialize1string json = JsonSerializer.Serialize(poco);
Deserialize1Poco poco = JsonSerializer.Deserialize<Poco>(json);
Specified property nameadd attribute [JsonPropertyName(name)] on Poco property.
e.g.12[JsonPropertyName("summary")]double Summarycurrency{get;init;}
will serialize as {"summary":1.0.0}
ignore nullignore propertie serialize when its value is null.
JsonSerializer.Serialize has second param:options to control behaviorset options.Def ...
单例模式
单例模式只允许被其自身实例化一次,且向外部提供了一个访问该实例的接口。
以下所有方法均通过public static Instance属性获取单例类实例。
实例检测12345678910111213141516public sealed class Singleton{ private static Singleton instance = null; private Singleton() { } public static Singleton Instance { get { if (instance == null) { instance = new Singleton(); } return instance; } }}
该方法在多线程下可能创建多个实例。当多个线程同时运行到if(insta ...
select all rows
create a class extends DbContext: MyDbContextand has a property DbSet<TableReord> MyDbSet;
12using var db = new MyDbContext();return MyDbContext.MyDbSet.ToList();
throw exception in try statement
https://stackoverflow.com/questions/47015693/how-to-fix-throw-of-exception-caught-locally
12345678function(){ try{ if(xxx){ throw new Exception("error"); } }catch(){ }}
when throw an exception in try statement, will show an warning:
1'throw' of exception caught locally. This inspection reports any instances of JavaScript throw statements whose exceptions are always caught by containing try statements. ...
get type of array items
https://stackoverflow.com/questions/46376468/how-to-get-type-of-array-items
1234type ARR = {a:number, b:number}[];type A = typeof ARR[number]; // A is {a:number, b:number}//ortype A = typeof ARR[0];
React多环境配置(create-react-app)
通过create-react-app创建的项目,自身支持多环境配置
详见: https://create-react-app.dev/docs/adding-custom-environment-variables/
注意
所有环境变量必须以REACT_APP_开头,env中只会保留NODE_ENV和REACT_APP_*的环境变量
You must create custom environment variables beginning with REACT_APP_. Any other variables except NODE_ENV will be ignored
使用react-scripts启动项目时,设置NODE_ENV是无效的
When you run npm start, it is always equal to ‘development’, when you run npm test it is always equal to ‘test’, and when you run npm run build to make a production bun ...
jest for typescript in vscode
add dependenciestypescript has included some deps, install deps below
ts-node
ts-jest
add config filets-jest support .ts config, just add file jest.config.ts to project root dir.
u have to told jest to use ts-jest to compile before runing, so config {preset: 'ts-jest'}.
the content like:
12345import type { Config } from '@jest/types';const config: Config.InitialOptions = { preset: 'ts-jest'};export default config;
testu can just run ...
Interceptor获取PathVariable
对于Spring,PathVariable是一种特殊的RequestAttribute,可通过HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE获取。
12Map<String, String> map = (Map<String, String>) request.getAttribute(HandlerMapping.URI_TEMPLATE_VARIABLES_ATTRIBUTE);String value= (String)pathVariables.get("varname");