fix: use separate relay caches for status
This commit is contained in:
parent
0eef646fe0
commit
f98a01f3f0
13 changed files with 49 additions and 38 deletions
src
22
src/cache.c
22
src/cache.c
|
@ -138,7 +138,7 @@ cache_invalidate_schedule(int schedule_id)
|
|||
|
||||
for(int i = 0; relays[i] != NULL; ++i)
|
||||
{
|
||||
cache_invalidate_relay(relays[i]->id);
|
||||
cache_invalidate_relay(relays[i]->id, -1);
|
||||
}
|
||||
|
||||
relay_free_list(relays);
|
||||
|
@ -147,26 +147,32 @@ cache_invalidate_schedule(int schedule_id)
|
|||
|
||||
|
||||
void
|
||||
cache_put_json_relay(int relay_id, char *relay_json)
|
||||
cache_put_json_relay(int relay_id, int status_relay, char *relay_json)
|
||||
{
|
||||
char key[32];
|
||||
sprintf(key, "relay_json:%d", relay_id);
|
||||
sprintf(key, "relay_json:%d:%d", relay_id, status_relay);
|
||||
cache_insert_value(key, relay_json);
|
||||
}
|
||||
|
||||
char*
|
||||
cache_get_json_relay(int relay_id)
|
||||
cache_get_json_relay(int relay_id, int status_relay)
|
||||
{
|
||||
char key[32];
|
||||
sprintf(key, "relay_json:%d", relay_id);
|
||||
sprintf(key, "relay_json:%d:%d", relay_id, status_relay);
|
||||
return cache_get_value(key);
|
||||
}
|
||||
|
||||
void
|
||||
cache_invalidate_relay(int relay_id)
|
||||
cache_invalidate_relay(int relay_id, int status_relay)
|
||||
{
|
||||
if(status_relay == -1)
|
||||
{
|
||||
cache_invalidate_relay(relay_id, 0);
|
||||
cache_invalidate_relay(relay_id, 1);
|
||||
return;
|
||||
}
|
||||
char key[32];
|
||||
sprintf(key, "relay_json:%d", relay_id);
|
||||
sprintf(key, "relay_json:%d:%d", relay_id, status_relay);
|
||||
cache_invalidate(key);
|
||||
|
||||
int controller_id = relay_get_controller_id_for_relay(relay_id);
|
||||
|
@ -215,7 +221,7 @@ cache_invalidate_tagged(int tag_id)
|
|||
int *relay_ids = junction_tag_get_relays_for_tag_id(tag_id);
|
||||
for(int i = 0; relay_ids[i] != 0; ++i)
|
||||
{
|
||||
cache_invalidate_relay(relay_ids[i]);
|
||||
cache_invalidate_relay(relay_ids[i], -1);
|
||||
}
|
||||
free(relay_ids);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue