You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by re...@apache.org on 2025/01/14 09:31:11 UTC

(sling-org-apache-sling-resourceresolver) 02/02: Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter

This is an automated email from the ASF dual-hosted git repository.

reschke pushed a commit to branch SLING-12615
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-resourceresolver.git

commit e54441c718816f469bfa52f353beb592f6571a61
Author: Julian Reschke <re...@apache.org>
AuthorDate: Tue Jan 14 10:30:18 2025 +0100

    Resource Resolver: refactor MapEntries - extract vanity path handling - extract bloom filter
---
 .../impl/mapping/VanityPathHandler.java            | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
new file mode 100644
index 0000000..4b6150a
--- /dev/null
+++ b/src/main/java/org/apache/sling/resourceresolver/impl/mapping/VanityPathHandler.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.resourceresolver.impl.mapping;
+
+/**
+ * Handles loading and caching of vanity paths.
+ */
+public class VanityPathHandler {
+
+    private static final int VANITY_BLOOM_FILTER_MAX_ENTRIES = 10000000;
+
+    private volatile MapConfigurationProvider factory;
+
+    private final byte[] bloomFilter;
+
+    /**
+     * @param factory {@link MapConfigurationProvider}
+     */
+    public VanityPathHandler(MapConfigurationProvider factory) {
+        this.factory = factory;
+        this.bloomFilter = BloomFilterUtils.createFilter(VANITY_BLOOM_FILTER_MAX_ENTRIES,
+                this.factory.getVanityBloomFilterMaxBytes());
+    }
+
+    public boolean cacheProbablyContains(String path) {
+        return BloomFilterUtils.probablyContains(this.bloomFilter, path);
+    }
+
+    public void cacheWillProbablyContain(String path) {
+        BloomFilterUtils.add(this.bloomFilter, path);
+    }
+ }