Skip to content

Caching with redis for API, auto reload caches by cron-job

Notifications You must be signed in to change notification settings

quangvinh1986/flask-redis-caching

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 

Repository files navigation

Lời mở đầu

Chức năng

Dự án này là phiên bản tiếp theo của dự án flask-celery-hr-noti cho phép thực hiện:

  • Thực hiện đặt cache các dữ liệu của các bảng thường xuyên truy xuất.
  • Cho phép reload lại cache tự động hàng ngày/hàng giờ bằng các cron-task
  • Hoặc chủ động reload lại cache từ end-point

Công nghệ sử dụng

  • Python 3.8
  • Flask 1.1.1
  • Celery 5.0.5
  • Redis: Sử dụng như message queue của celery và là nơi lưu trữ cache của hệ thống.
  • PostgreSQL (Để đảm bảo việc có thể phình to về mặt chức năng, database của bài toán thay đổi thành RDBMS)

Về dự án:

Phiên bản demo (DONE):

{
  "data": [
    {
      "LOCATION_ID": 1700,
      "MANAGER_ID": 200,
      "DEPARTMENT_NAME": "Administration",
      "DEPARTMENT_ID": 10
    },
    {
      "LOCATION_ID": 1800,
      "MANAGER_ID": 201,
      "DEPARTMENT_NAME": "Marketing",
      "DEPARTMENT_ID": 20
    }
  ],
  "dateReceived": "2021-04-12 00:10:49",
  "isCache": false
}      
  • Dùng API lấy ra được dữ liệu trong redis.

ex: http://0.0.0.0:5001/myApi/hrApi/departments?isReloadCache=false

http://0.0.0.0:5001/myApi/hrApi/departments

{
  "data": [
    {
      "LOCATION_ID": 1700,
      "MANAGER_ID": 200,
      "DEPARTMENT_NAME": "Administration",
      "DEPARTMENT_ID": 10
    },
    {
      "LOCATION_ID": 1800,
      "MANAGER_ID": 201,
      "DEPARTMENT_NAME": "Marketing",
      "DEPARTMENT_ID": 20
    }
  ],
  "dateReceived": "2021-04-12 00:10:49",
  "isCache": true
}      

Phiên bản nâng cao (DONE: 20210420)

  • Cho phép reload cache từ cron-job (task reload_department_cache)

  • Viết function demo cho phép các action dùng trong background task sử dụng cache như khi gọi từ API (task get_departments)

About

Caching with redis for API, auto reload caches by cron-job

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages