The increase of the lap, deletion, reform, and check the function

Function The file: framework / function / cache.mysql.func.php

Currently, the individual’s personal call:

$ setting = $ this-> Module [‘config’];

$ aaaaa = $ setting [‘Copyright’];

in the micro WeChat public number system The inside can be divided into three types cache: Save to database caching in Database Table Core_Cache, save to file cache and Memcahe cache, this tutorial is a database cache, which is also the default cache for the OBQ configuration.

Because the function of processing the database cache is relatively simple, the PHPOS WeChat network creates these functions into a tutorial. Because it is an operation of the database table, how to operate the table, nothing more than the table record, delete, modify, and queries, so corresponding to the database buffer function also has inserted cache data, delete cache data, modify cache data And query cache data operations.

The cache data in the micro WeChat public account is saved to the cache table core_cache, that is, the following functions are the increase in this table, delete , Change and check the operation.

First, insert (write) cache Data


Cache_WRITE ($ key, $ data) function: This is already explained in this site, and it will not explain more here.

LOAD () -> FUNC (‘cache.mysql’);

cache_write (‘phpos’, array “WeChat development ‘,’ url ‘=>’ ‘,’ title ‘=> array (‘ WeChat development”, ‘WeChat public number’)


Second, delete cache data

Delete function: cache_delete ($ key)


This function is Yes: Delete a record in the Core_Cache table.

$ key is the value of the field key in the table to be deleted, for example, to delete the PHPOS record, $ Key = ‘phpos’.

The SQL statement used in this function is:

delete from ‘. TableName (‘ Core_Cache ‘).’ Where `Key` =: Key

This parameter $ key is the condition to be deleted, so as long as you pass a value $ key, you can delete the record corresponding to the key field in the table.

In this function, the database query function PDO_QUERY ($ SQL, $ Params) encapsulated in this function, this function is similar to Mysql_Query inside the process ( ) Execute a SQL statement.

Delete field phpos correspondence:

LOAD () -> FUNC (‘cache.mysql’);

Cache_DEletE (‘phpos’);

Removes records in the entire cache table, or delete records containing the same name.

Delete function: cache_clean ($ prefix = ”)

The above function is to delete a certain piece Record, and this function deletes the entire table or contains a record of the value like phpos:, web:, site: and other fields.

1) If the $ prefix is ​​empty, delete the data in a Core_Cache table.

and, delete data stored in global variable $ _W:

IF ($ results) {

Unset ($ _ w [‘cache’]);

, $ _ w [‘cache’] is in file .php defined:

IF (! in_Array ($ _ w [‘config’] [‘setting’] [‘cache’], array (‘mysql’, ‘file’, ‘Memcache’))) {

$ _W [‘config’] [‘setting’] [‘cache’] = ‘mysql’;


The $ _W [‘config’] [‘setting’] [‘cache’] inside this condition is configured in the configuration file data / config.php, the default is mysql, indicating that “database cache” is used using cache data.

2) If $ prefix is ​​not available, the data that matches {$ prefix}:%.

LOAD () -> FUNC (‘cache.mysql’);

Cache_clean (‘Website’);

cache_clean ();

Fourth, query cache data

1) Read Cache Data Function:

Read Table A cache data:

Select `value` from ‘. Tablename (‘ core_cache ‘).’ Where` key` =: key ‘

From this SQL statement, you can see that this function queries is the value corresponding to the key in the table core_cache, and uses the function IUNSERIALIZER ($ VAL) to query the serialization String is converted into a critical sequence.

LOAD () -> FUNC (‘cache.mysql’);

Print_R (Cache_READ (‘Website’));

Result: Array ([URL] => [Title] => WeChat Network)

2) Query all qualified cache data functions:


Query SQL statement:

$ SQL = ‘SELECT * FROM’. TABLENAME ‘Core_Cache’). ‘WHERE `Key` Like: Key’;

$ params = array ();

$ params [‘: key’] =” {$ prefix}% ”

$ = PDO_FETCHALL ($ SQL, $ Params);

From the above code, it can be seen that this function is the Query field key. The value contains all records of {$ prefix}, where functions PDO_FETCHALL () queries all meetings.

Finally, returned $ Result and an array.

LOAD () -> FUNC (‘cache.mysql’);

Print_R (Cache_Search);

Result: Array ([Website] => Array ([URL] => [Title] => WeChat network)

5. Update cache data

In this file cache.mysql.func.php, we did not discover update cache data, can you update? In fact, write data function cache_write () in the call function PDO_INSERT (‘Core_Cache’, $ Record, TWhen RUE is used, the third parameter TRUE inserted into the data function is used. If this parameter is used, use the Replace INTO statement into the data. This SQL statement will determine whether there is a certain data in the table. If there is, it is deleted. Then, insert the data to be inserted into the table into the table.

So, in fact, this write data function itself has the function of updating the data, so it is not indeed defined in this file and is not individually defined.

© Copyright Notice
Just support it if you like
comment Grab the couch

Please log in to comment