简体   繁体   中英

Memcached Key generation - Java

My application has quite a good number of tables in DB. What is the efficient way of key generation for Memcached? Because, whenever we update a table's data, we have to see if there is any cached data related to that table and clear it. Also I need to take care of join queries because if either of the tables involved in a cached join is modified, the cached data should be cleared too.

Key could be with the DB_TABLE NAME_PrimaryKey-field. Where the PrimaryKey-field is provided with the "primary key" of the table.
In the custom client class say CustomAppCache have inner class say CacheKeyGen this can be defined with the properties having database, tableName, primaryKeyField. Now the memcached will have the data with the key as DB_TABLE_NAME_PrimaryKey-field and the table data as the value.

While using the setCache set the data to the memcached with all the data of the table.

While using the getCache check for matching the pattern of the requisite and perform the intended operation like delete from the cache and reload it.
This should solve the key generation problem.
Let me know if this solves your key gen problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM