小编kt1*_*t14的帖子

Django Cache (Redis) 在数据更改时自动刷新

如果对与缓存数据相关的数据库进行了任何更改,是否有任何方法可以通知 django 刷新缓存?我找到了这篇文章,没有最新的答案,提到的 django 版本是 1.6。我查看了缓存文档,但没有找到与问题直接相关的任何内容。

我的问题是如果我缓存数据库查询的结果并且在缓存超时之间添加了新记录怎么办

from django.core.cache import cache

results = MyModel.objects.all() # 4 count
cache.set('results', results ) # Cached for 5 mins

# Mean while records have been added to MyModel table

results = MyModel.objects.all() # 6 count
cache.get('results') # 4 count and would not be updated for 5 mins
Run Code Online (Sandbox Code Playgroud)

有没有办法检查是否有任何添加到数据库和缓存刷新,无论何时从数据库中添加或删除记录?

我有将近 10 张表,这可能很重要。无论何时更改记录,都必须更新缓存。

非常感谢任何帮助或建议。

项目堆栈:

Django: 1.9
Python: 3.5
Redis: 2.8 (Cache Database)
Postgres: 9.5 (Main Database)
Run Code Online (Sandbox Code Playgroud)

python django postgresql caching redis

7
推荐指数
1
解决办法
2437
查看次数

在set()之后不执行Firestore then()函数

我正在使用set功能在Firestore中创建一个新文档。我想在set函数将数据推入数据库后使用文档数据。

            // Add each record to their respective heads
        let docRef = headCollectionRef.doc(data.headSlug).collection(recordsCollection)
            .doc(String(data.recordData.sNo))
        docRef.set(data).then(docSnap => {
            agreementData.push(
                docSnap.get().then(data => {
                    return data
                })
            )
        })
Run Code Online (Sandbox Code Playgroud)

中没有任何then()内容被执行。

任何帮助深表感谢

node.js firebase google-cloud-firestore

2
推荐指数
1
解决办法
846
查看次数

Kubernetes client-python 创建服务错误

我正在尝试为我node-js-deployment在 GCE 主机 Kubernetes Cluster 中命名的部署之一创建一个新服务

我按照文档来create_namespaced_service

这是服务数据:

{
    "kind": "Service",
    "apiVersion": "v1",
    "metadata": {
        "name": "node-js-service"
    },
    "spec": {
        "selector": {
            "app": "node-js"
        },
        "ports": [
            {
                "protocol": "TCP",
                "port": 80,
                "targetPort": 8000
            }
        ]
    }
}
Run Code Online (Sandbox Code Playgroud)

这是创建服务的 Python 函数

api_instance = kubernetes.client.CoreV1Api()
namespace = 'default'  

body = kubernetes.client.V1Service()  # V1Serice

# Creating Meta Data
metadata = kubernetes.client.V1ObjectMeta()
metadata.name = "node-js-service"

# Creating spec 
spec = kubernetes.client.V1ServiceSpec()

# Creating Port object
ports = kubernetes.client.V1ServicePort()
ports.protocol = …
Run Code Online (Sandbox Code Playgroud)

python-3.x kubernetes google-kubernetes-engine

1
推荐指数
1
解决办法
2971
查看次数