Files
windmill/backend/migrations/20250902070305_variable_resource_cache_notifications.up.sql
claude[bot] db36a323a7 feat(perf): add 60-second local cache for variables and resources(#6511)
* feat: add 60-second cache for variables and resources with PostgreSQL invalidation

- Add new var_resource_cache module with 60-second TTL
- Implement PostgreSQL NOTIFY/LISTEN for immediate cache invalidation
- Cache get_variable() for non-secret, non-encrypted reads
- Cache get_resource_value() for all read operations
- Add database triggers on variable/resource table changes
- Initialize cache system in main.rs after database connection
- Add Clone derive to ListableVariable for cache compatibility

Performance benefits:
- Avoids database queries on cache hits
- Immediate invalidation ensures data consistency
- Selective caching respects security constraints

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* refactor: move cache to API layer with allow_cache query param

- Move variable/resource cache from windmill-common to windmill-api
- Add allow_cache query parameter to variables and resources endpoints
- Follow raw script cache pattern with timestamp + value structure
- Create proper database migration for notification triggers
- Include encrypted values in cache when appropriate
- Only activate caching when explicitly requested

Co-authored-by: Ruben Fiszel <rubenfiszel@users.noreply.github.com>

* refactor: move cache to API layer with allow_cache query param

Move PostgreSQL LISTEN logic to main.rs following established pattern
- Remove custom listener initialization from cache module
- Add cache invalidation channels to centralized notification handler
- Simplified cache module to only handle cache operations
- Follow raw script cache pattern for notification handling

Co-authored-by: Ruben Fiszel <rubenfiszel@users.noreply.github.com>

---------

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Ruben Fiszel <rubenfiszel@users.noreply.github.com>
2025-09-02 07:48:03 +00:00

36 lines
1.3 KiB
PL/PgSQL

-- Add up migration script here
-- Create notification function for variable and resource cache invalidation
CREATE OR REPLACE FUNCTION notify_var_resource_cache_change()
RETURNS TRIGGER AS $$
BEGIN
IF TG_TABLE_NAME = 'variable' THEN
PERFORM pg_notify('var_cache_invalidation',
json_build_object(
'workspace_id', COALESCE(NEW.workspace_id, OLD.workspace_id),
'path', COALESCE(NEW.path, OLD.path),
'operation', TG_OP
)::text
);
ELSIF TG_TABLE_NAME = 'resource' THEN
PERFORM pg_notify('resource_cache_invalidation',
json_build_object(
'workspace_id', COALESCE(NEW.workspace_id, OLD.workspace_id),
'path', COALESCE(NEW.path, OLD.path),
'operation', TG_OP
)::text
);
END IF;
RETURN COALESCE(NEW, OLD);
END;
$$ LANGUAGE plpgsql;
-- Create triggers for variable table
CREATE TRIGGER variable_cache_invalidate_trigger
AFTER INSERT OR UPDATE OR DELETE ON variable
FOR EACH ROW EXECUTE FUNCTION notify_var_resource_cache_change();
-- Create triggers for resource table
CREATE TRIGGER resource_cache_invalidate_trigger
AFTER INSERT OR UPDATE OR DELETE ON resource
FOR EACH ROW EXECUTE FUNCTION notify_var_resource_cache_change();