How does the data Access layer (DAL) gracefully coordinate access to cache databases (such as Redis) and persistent databases (such as MySQL)?

Source: Internet
Author: User
Suppose the DAL uses PHP for example.

Originally using PHP alone to operate MySQL, now need to press the server, consider adding a redis, but at the same time facing the two data source access strategy generated doubts, hope to help comb.

It's better to explain it in pseudo-code, thank you.

Reply content:

Suppose the DAL uses PHP for example.

Originally using PHP alone to operate MySQL, now need to press the server, consider adding a redis, but at the same time facing the two data source access strategy generated doubts, hope to help comb.

It's better to explain it in pseudo-code, thank you.

Just think of Redis as a cache, no need to write it in the Dal (I don't know what the dal means, just use DAO, Ar,orm, listen to the names are similar things?). ), just to expand it in the form of caching, such as inheriting your cache class, if it is also useful for persistent storage needs, to inherit the Dal class, with Redis to implement it, if used as a queue, or intersection and set, counter, etc., also to the Redis database to implement the existing interface.

Finally, a generic portal file is used to invoke the different implementations by constructing the method.

Pseudo code will not write, since PHP directly paste Open source project Bar Yii2-redis, look at the activerecord.php and cache.php, presumably this is the idea.

  • Related Article

    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.