How does the data access layer (DAL) elegantly coordinate access to cache databases (such as redis) and persistent databases (such as mysql )?

Source: Internet
Author: User
Suppose dal uses php as an example. I used to use php to operate mysql separately. Now I need to squeeze the server and consider adding a redis instance. However, I am confused about the access policies of the two data sources. I hope to help me sort it out. It is better to explain it with pseudo code. Thank you. Suppose dal uses php as an example.

I used to use php to operate mysql separately. Now I need to squeeze the server and consider adding a redis instance. However, I am confused about the access policies of the two data sources. I hope to help me sort it out.

It is better to explain it with pseudo code. Thank you.

Reply content:

Suppose dal uses php as an example.

I used to use php to operate mysql separately. Now I need to squeeze the server and consider adding a redis instance. However, I am confused about the access policies of the two data sources. I hope to help me sort it out.

It is better to explain it with pseudo code. Thank you.

Simply using redis as a cache doesn't have to be written in the DAL (I don't know what the DAL means. I only use DAO, AR, ORM, and heard the name is similar ?), Expand it only in the form of Cache, such as inheriting your Cache class. If you still need to use it for permanent storage, inherit the DAL class and use redis to implement it, if you use a queue, or intersection collection, counters, and so on, you can also use the redis database to implement the existing interface.

Finally, we use a universal portal file to call different implementations through the constructor.

Pseudo code will not write, since PHP directly paste open source project Yii2-redis, look at the ActiveRecord. php and Cache. php, the idea is probably like this.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.