Caching SearXNG Version 2
This revision is from 2024/07/30 22:23. You can Restore it.
In version 2 the caching filenames are hashed which means that international characters and symbols are supported and less likely to break searx.
- webapp.py in /usr/local/searxng/searxng-src/searx/webapp.py : def search()
- __init__.py in /usr/local/searxng/searxng-src/searx/search/__init__.py : class Search
sudo mkdir -p /usr/local/searxng/searxng-src/searx/cache
for i in {0..255}; do sudo mkdir -p /usr/local/searxng/searxng-src/searx/cache/$(printf "%02x" $i); done
sudo chown -R root:searxng /usr/local/searxng/searxng-src/searx/cache
sudo chmod -R 777 /usr/local/searxng/searxng-src/searx/cache
import hashlib
fname = request.form['q'] + str(search_query.pageno) + str(search_query.categories[0])
# Generate a hash of the search term
hash_object = hashlib.md5(fname.encode())
hex_dig = hash_object.hexdigest()
subdirectory = hex_dig[:2] # Use the first 2 characters of the hash as the subdirectory name
cache_dir = os.path.abspath(os.path.join("cache", subdirectory))
if not os.path.exists(cache_dir):
os.makedirs(cache_dir)
file_path = os.path.join(cache_dir, fname)