cache

package
v0.0.0-...-377a973 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 30, 2020 License: BSD-3-Clause Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	CacheObj = map[string]*DBcache{} //缓存表对象,用于rpc,grpc
)

Functions

func BinarySearchAsc

func BinarySearchAsc(data []*SliceCache, findData string) int

---------------------数据查找---------------------------------------------------- 二分查找.(数据原已排序,数据是升序)

func BinarySearchDesc

func BinarySearchDesc(data []*SliceCache, findData string) int

二分查找.(数据原已排序,数据是降序)

func FindLocationAsc

func FindLocationAsc(data []*SliceCache, start, end, cur int) int

二分法插入排序,查找位置.(升序排序).start开始位置,end结束位置,cur当前位置

func FindLocationDesc

func FindLocationDesc(data []*SliceCache, start, end, cur int) int

二分法插入排序,查找位置.(降序排序).start开始位置,end结束位置,cur当前位置

func QuickSortIndexAsc

func QuickSortIndexAsc(data []*SliceCache, left, right int)

快速排序,递归

func QuickSortIndexDesc

func QuickSortIndexDesc(data []*SliceCache, left, right int)

快速排序(降序排序),递归

func QuickSortIndexGoAsc

func QuickSortIndexGoAsc(data []*SliceCache, left, right int)

快速排序,递归

func QuickSortIndexGoDesc

func QuickSortIndexGoDesc(data []*SliceCache, left, right int)

并发快速排序(降序排序),递归

func Swap

func Swap(data []*SliceCache, i, j int)

数据交换

Types

type AsyncSql

type AsyncSql struct {
	// contains filtered or unexported fields
}

异步更新数据库

type DBcache

type DBcache struct {
	//基础配置信息
	DbConn      *sql.DB                //数据库对象
	TableConfig conf.CacheTable        //[配置文件cache.conf]保存缓存数据表信息
	ColumnInfo  map[string]*columnInfo //数据库缓存表中列的信息
	CacheType   string                 //用于分页查询,缓存类型:一.slice切片,二.sliceNotDel切片(不删除,只记录),三.link链表

	//map数据缓存对象[主缓存对象]
	DbCache sync.Map //用来缓存的表数据
	//链表缓存对象
	LinkDbCache LinkCache //链表保存缓存数据[用于页面分页显示](链表,插入和删除快,但查找,修改没切片数据快.适用于插入删除多.数据量大)
	//切片缓存对象(切片数组优点,因为内存是连续的,查找,修改快,但是插入和删除慢.适用于查询多.数据量少)
	SliceDbCache []*SliceCache //用来根据行号查询缓存,[用于页面分页显示]
	//切片缓存类型是[sliceNotDel]
	DelRowNum map[int]bool //(缓存是切片SliceDbCache,并且缓存类型是[sliceNotDel])保存已删除行的行号,当有删除行时,只是把删除的行号保存.未进行切片的删除,因为切片的删除会影响性能.但是这样的缺点是未排序.
	RowCount  int64        //总行数
	RwMutex   sync.RWMutex //读写锁
	// contains filtered or unexported fields
}

func NewDBcache

func NewDBcache(db *sql.DB, tableName string) (dbCache *DBcache, err error)

新建缓存对象,根据配置文件中,配置的数据库表名.

func (*DBcache) Close

func (d *DBcache) Close()

关闭打开的对象

func (*DBcache) DelDbRow

func (d *DBcache) DelDbRow(key string) (n int64, err error)

根据主键值,删除数据库中该行数据.

func (*DBcache) DelRow

func (d *DBcache) DelRow(Pkey string) (n int64, err error)

根据主键值,删除该行数据.

func (*DBcache) DelSliceDbCache

func (d *DBcache) DelSliceDbCache(pkeyValue string)

缓存类型是slice切片 (该函数仅于分页查询),删除切片中的数据

func (*DBcache) DelSliceDbCacheRecord

func (d *DBcache) DelSliceDbCacheRecord(pkeyValue string)

缓存类型是sliceNotDel切片(不删除,只记录) (该函数仅于分页查询),当有删除行时,只是把删除的行号保存.未进行切片的删除,因为切片的删除会影响性能.

func (*DBcache) GetColumn

func (d *DBcache) GetColumn(Pkey string, column string) (result string, err error)

根据主键,获取一列的数据.

func (*DBcache) GetColumnType

func (d *DBcache) GetColumnType(column string) (columnType string)

获取列在数据库中的类型.

func (*DBcache) GetCondition

func (d *DBcache) GetCondition(where string, operator string) (whereCondition [][]string, err error)

获取and或or二边的条件表达式

func (*DBcache) GetMultipageRows

func (d *DBcache) GetMultipageRows(startPage int, pageNum int, pageSize int) (result []map[string]string)

用于分页,根据指定开始页,获取多少页,每页行数.返回数据.参数说明:startPage,开始页,pageNum多少页,pageSize参数是每页行数大小

func (*DBcache) GetOnePageRows

func (d *DBcache) GetOnePageRows(page int, pageSize int) (result []map[string]string)

用于分页,根据页码和每页行数大小,返回数据.参数说明:page参数是页码,pageSize参数是每页行数大小

func (*DBcache) GetPageCount

func (d *DBcache) GetPageCount(pageSize int) (result int)

用于分页,获取总页数.pageSize参数是每页行数大小

func (*DBcache) GetRow

func (d *DBcache) GetRow(Pkey string) (result map[string]string, err error)

根据主键,获取该行的数据.

func (*DBcache) GetRowBetween

func (d *DBcache) GetRowBetween(start int, end int) (result []map[string]string)

(该函数仅于分页显示,提取数据)从缓存中,获取指定的行,开始行-结束行.(不包括结束行)并不是与数据库中行号一致. 因为从数据库中检索数据时,数据先后不一定.这只是缓存的行号.目的是一样.不影响使用.

func (*DBcache) GetRowNum

func (d *DBcache) GetRowNum(pkeyValue string) (i int)

缓存类型是slice切片 (该函数仅于分页查询),获取用于分页缓存中数据的行号

func (*DBcache) GetRowNumRecord

func (d *DBcache) GetRowNumRecord(pkeyValue string) (i int)

缓存类型是sliceNotDel切片(不删除,只记录) (该函数仅于分页查询),获取用于分页缓存中数据的行号

func (*DBcache) GetRowNumRecord2

func (d *DBcache) GetRowNumRecord2(pkeyValue string) (i int)

func (*DBcache) GetSqlStr

func (d *DBcache) GetSqlStr(condition string) (SqlStr string)

根据表达式,得到SQL语句的字符串.

func (*DBcache) GetWhere

func (d *DBcache) GetWhere(where string) (result []map[string]string, err error)

根据where条件,获取多行数据.

func (*DBcache) GetWhereCondition

func (d *DBcache) GetWhereCondition(where string, isAnd, isOr bool) (whereCondition [][]string, err error)

根据where条件中,and和or获得条件表达式

func (*DBcache) GetWhereValue

func (d *DBcache) GetWhereValue(isAnd, isOr bool, whereCondition [][]string, rowMap *sync.Map, result *[]map[string]string)

根据where条件表达式,检查表达式是否成立,并得到数据.

func (*DBcache) InsertDbRow

func (d *DBcache) InsertDbRow(condition string) (n int64, err error)

插入一行数据到数据库.

func (*DBcache) InsertRow

func (d *DBcache) InsertRow(condition string) (n int64, err error)

插入一行数据.

func (*DBcache) SplitCondition

func (d *DBcache) SplitCondition(str string, operator string) (result []string, err error)

分割表达式 以(and,or,逗号等分割)分解条件表达式,保存于切片,例如:user=xiaoming,pwd=1345534 分解为每个单独的字符串,例:user=xiaoming,分解成三个,user,=,xiaoming

func (*DBcache) SplitString

func (d *DBcache) SplitString(str string, operator string) (slices []string)

分解字符串保存于切片中,去除两边的空格.

func (*DBcache) UpdateColumn

func (d *DBcache) UpdateColumn(Pkey string, column string, value string) (n int64, err error)

根据主键,更新一列的数据.

func (*DBcache) UpdateColumns

func (d *DBcache) UpdateColumns(Pkey string, where string) (n int64, err error)

根据主键,更新多列数据.

func (*DBcache) UpdateDbcolumn

func (d *DBcache) UpdateDbcolumn(Pkey string, column string, value string) (n int64, err error)

根据主键,更新数据库中一列.

func (*DBcache) UpdateDbcolumns

func (d *DBcache) UpdateDbcolumns(Pkey string, condition string) (n int64, err error)

根据主键,更新数据库中多列.

type DataAsync

type DataAsync struct {
	DataAsyncConf      conf.DataAsync //[配置文件cache.conf]保存数据库数据异步信息.
	AsyncSqlchan       chan *AsyncSql //异步数据库同步管道
	AsyncFileObj       *os.File       //异步数据库同步,保存需要更新的SQL语句文件对象.
	AsyncFailedFileObj *os.File       //异步数据库同步,保存失败的需要更新的SQL语句文件对象.
}

func NewDatAsync

func NewDatAsync() *DataAsync

func (*DataAsync) Close

func (d *DataAsync) Close()

关闭打开的对象

func (*DataAsync) InitAsync

func (d *DataAsync) InitAsync(db *sql.DB, tableName string) (err error)

初始化异步同步信息.

type LinkCache

type LinkCache struct {
	// contains filtered or unexported fields
}

双链表缓存

func NewLinkCache

func NewLinkCache() LinkCache

新建一个双链表头.

func (*LinkCache) DeleteIndexNode

func (l *LinkCache) DeleteIndexNode(index int64) bool

删除一个节点,按照索引

func (*LinkCache) DeleteNode

func (l *LinkCache) DeleteNode(node *Node) bool

删除一个节点

func (*LinkCache) DeleteNodePkey

func (l *LinkCache) DeleteNodePkey(Pkey string) bool

删除一个节点,根据主键.

func (*LinkCache) FindString

func (l *LinkCache) FindString(Pkey string) (out string)

根据输入值,在链表中查找.

func (*LinkCache) GetAllNode

func (l *LinkCache) GetAllNode() []*Node

得到链表中所有节点

func (*LinkCache) GetFirstNode

func (l *LinkCache) GetFirstNode() *Node

返回第一个节点

func (*LinkCache) GetIndexNode

func (l *LinkCache) GetIndexNode(index int64) *Node

得到索引index的节点

func (*LinkCache) GetLength

func (l *LinkCache) GetLength() int64

返回链表长度

func (*LinkCache) GetNodeBetween

func (l *LinkCache) GetNodeBetween(start int64, end int64) []*Node

得到链表中指定开始到结束的节点

func (*LinkCache) InsertHead

func (l *LinkCache) InsertHead(node *Node)

从头部插入

func (*LinkCache) InsertNodeAfter

func (l *LinkCache) InsertNodeAfter(dest *Node, node *Node) bool

插入一个节点到目的节点后面

func (*LinkCache) InsertNodeAfterAtPkey

func (l *LinkCache) InsertNodeAfterAtPkey(pkey interface{}, node *Node) bool

根据主键,插入一个节点到目的主键数据值后面

func (*LinkCache) InsertNodeAsc

func (l *LinkCache) InsertNodeAsc(node *Node) bool

插入一个节点,根据按sortColumn升序排列的数据.

func (*LinkCache) InsertNodeBefore

func (l *LinkCache) InsertNodeBefore(dest *Node, node *Node) bool

插入一个节点到目的节点前面

func (*LinkCache) InsertNodeBeforeAtPkey

func (l *LinkCache) InsertNodeBeforeAtPkey(pkey interface{}, node *Node) bool

根据主键,插入一个节点到目的主键数据值前面

func (*LinkCache) InsertNodeDesc

func (l *LinkCache) InsertNodeDesc(node *Node) bool

插入一个节点,根据按sortColumn降序排列的数据.

func (*LinkCache) InsertTail

func (l *LinkCache) InsertTail(node *Node)

直接从尾部开始插入

func (*LinkCache) InsertTailFromHead

func (l *LinkCache) InsertTailFromHead(node *Node)

从头部开始遍历到尾部插入,效率没有InsertTail()这个函数好,因为每次都要从头遍历到最后

type Node

type Node struct {
	// contains filtered or unexported fields
}

双向链表.行数据节点

func NewNode

func NewNode(rowNum int64, pkey string, sortColumn string, row *sync.Map) *Node

新建一个节点

func (*Node) Next

func (r *Node) Next() *Node

返回下一下节点

func (*Node) Pkey

func (r *Node) Pkey() string

返回pkey数据

func (*Node) Pre

func (r *Node) Pre() *Node

返回上一个节点

func (*Node) RowNum

func (r *Node) RowNum() int64

返回rowNum数据

func (*Node) RowValue

func (r *Node) RowValue() *sync.Map

返回行数据

type SliceCache

type SliceCache struct {
	Pkey       string    //主键值
	SortColumn string    //排序列值
	SortMode   string    //排列方式
	RowMap     *sync.Map //数据库中行的数据
}

切片缓存数据

func BinarySearchSortAsc

func BinarySearchSortAsc(data []*SliceCache) []*SliceCache

---------------------二分法插入排序(升序排序)---------------------------------------------------- 二分法插入排序.(升序排序)[用在内存中,不要用在硬盘等外存中,例如硬盘文件,顺序更快.]

func BinarySearchSortDesc

func BinarySearchSortDesc(data []*SliceCache) []*SliceCache

---------------------二分法插入排序(降序排序)---------------------------------------------------- 二分法插入排序.(降序排序)[用在内存中,不要用在硬盘等外存中,例如硬盘文件,顺序更快.]

func BinarySearchSortIndexAsc

func BinarySearchSortIndexAsc(data []*SliceCache, start, end int) []*SliceCache

---------------------二分法插入排序[指定区间](升序排序)---------------------------------------------------- 对指定区间数据,利用二分法插入排序.

func BinarySearchSortIndexDesc

func BinarySearchSortIndexDesc(data []*SliceCache, start, end int) []*SliceCache

---------------------二分法插入排序[指定区间](降序排序)---------------------------------------------------- 对指定区间数据,利用二分法插入排序.

func InsertSortAsc

func InsertSortAsc(data []*SliceCache) []*SliceCache

---------------------插入排序(升序排序)---------------------------------------------------- 插入排序(升序排序)

func InsertSortDesc

func InsertSortDesc(data []*SliceCache) []*SliceCache

---------------------插入排序(降序排序)---------------------------------------------------- 插入排序(降序排序)

func InsertSortPkeyAsc

func InsertSortPkeyAsc(data []*SliceCache) []*SliceCache

插入排序,按主键排序(升序排序)

func InsertSortPkeyDesc

func InsertSortPkeyDesc(data []*SliceCache) []*SliceCache

插入排序,按主键排序(降序排序)

func MergeAsc

func MergeAsc(one, two []*SliceCache) []*SliceCache

归并排序(升序排序).

func MergeDesc

func MergeDesc(one, two []*SliceCache) []*SliceCache

归并排序(降序排序).

func MergeSortAsc

func MergeSortAsc(data []*SliceCache) []*SliceCache

---------------------归并排序(升序排序)---------------------------------------------------- 归并排序(升序排序). (缺点,会多占空间)

func MergeSortDesc

func MergeSortDesc(data []*SliceCache) []*SliceCache

---------------------归并排序(降序排序)---------------------------------------------------- 归并排序(降序排序). (缺点,会多占空间)

func MergeSortGoAsc

func MergeSortGoAsc(data []*SliceCache) []*SliceCache

并发归并排序(升序排序). (缺点,会多占空间)

func MergeSortGoDesc

func MergeSortGoDesc(data []*SliceCache) []*SliceCache

并发归并排序(降序排序). (缺点,会多占空间)

func QuickSortAsc

func QuickSortAsc(data []*SliceCache) []*SliceCache

---------------------快速排序(升序排序)---------------------------------------------------- 快速排序(升序排序)

func QuickSortDesc

func QuickSortDesc(data []*SliceCache) []*SliceCache

---------------------快速排序(降序排序)---------------------------------------------------- 快速排序(降序排序)

func QuickSortGoAsc

func QuickSortGoAsc(data []*SliceCache) []*SliceCache

---------------------并发快速排序(升序排序)---------------------------------------------------- 并发快速排序(升序排序)

func QuickSortGoDesc

func QuickSortGoDesc(data []*SliceCache) []*SliceCache

---------------------并发快速排序(降序排序)---------------------------------------------------- 并发快速排序(降序排序)

func SimpleQuickSortGoAsc

func SimpleQuickSortGoAsc(data []*SliceCache) (result []*SliceCache)

---------------------并发简单快速排序(升序排序)---------------------------------------------------- 并发简单快速排序(升序排序),一般的快速排序.没优化.(缺点,会多占空间)

func SimpleQuickSortGoDesc

func SimpleQuickSortGoDesc(data []*SliceCache) (result []*SliceCache)

---------------------并发简单快速排序(降序排序)---------------------------------------------------- 并发简单快速排序(降序排序).一般的快速排序.没优化.(缺点,会多占空间)

type WaitResult

type WaitResult struct {
	// contains filtered or unexported fields
}

等待数据库返回执行结果.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL