def delete_course_memcached(id): """ 删除特定课程的缓存(课程被删除后自动执行) """ course = Courses.query.get_or_404(id) lru.delete(course) lru.save()
def update_course_memcached(id): """ 更新特定id课程的缓存 """ course = Courses.query.get_or_404(id) lru.delete(course) lru.set(course.to_json(), [course.name, course.teacher]) lru.save()
def read_data2_memcached(): """ 将postgresql数据库中的课程搜索数据 读入LRU并写入硬盘(数据库读取开销) """ courses = Courses.query.all() for course in courses: lru.set(course.to_json(), [course.name, course.teacher]) lru.save() # 数据存储硬盘
def delete_course(id): course = Courses.query.get_or_404(id) if request.method == "DELETE": db.session.delete(course) db.session.commit() # 自动清除缓存 lru.delete(course) lru.save() return jsonify({"message": "该课程已被删除"})
def delete_course(id): course = Courses.query.get_or_404(id) if request.method == "DELETE": db.session.delete(course) db.session.commit() # 自动清除缓存 lru.delete(course) lru.save() return jsonify({'message': '该课程已被删除'})