Skip to content

Commit

Permalink
Merge pull request #97 from Thorfusion/dev
Browse files Browse the repository at this point in the history
Update to 1.6.1
  • Loading branch information
maggi373 authored Dec 13, 2024
2 parents 3b9fd08 + f4ada3c commit bc20d97
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
8 changes: 4 additions & 4 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ NEW_USER=True
TECHNIC_MIGRATION=True

# Caching options
# Set the cache eviction algorithm. Options are FIFO, LFU, LRU or RR. Default is LRU.
CACHE_ALGORITHM=LRU

# Set the cache maximum size. Default is 100.
CACHE_SIZE=100
CACHE_SIZE=100

# Set the cache TTL in seconds. Default is 300 seconds.
CACHE_TTL=300
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ Solder.py uploads the modfiles to a volume in the container

#### Caching options

Set the cache eviction algorithm. Options are FIFO, LFU, LRU or RR. Default is LRU.
Set the cache time to live, default 300 (seconds)

```bash
-e CACHE_ALGORITHM=LRU
-e CACHE_TTL=300
```

Set the cache maximum size. Default is 100.
Set the cache maximum size ie how much memory usage. Default is 100 (MB).

```bash
-e CACHE_SIZE=100
Expand Down
14 changes: 7 additions & 7 deletions api.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from flask import Blueprint, jsonify, request
from cachetools import cached
from cachetools import cached, TTLCache
from models.key import Key
from models.mod import Mod
from models.modpack import Modpack
from models.common import solderpy_version, public_repo_url
from models.common import cache_type, cache_size
from models.common import cache_size, cache_ttl

api = Blueprint("api", __name__)

Expand Down Expand Up @@ -35,7 +35,7 @@ def verify_key(key: str = None):


@api.route("/api/modpack")
@cached(cache_type(cache_size), key=lambda: str(request.args.get("cid")) + str(request.args.get('include')) + str(request.args.get('k')))
@cached(TTLCache(cache_size, cache_ttl), key=lambda: str(request.args.get("cid")) + str(request.args.get('include')) + str(request.args.get('k')))
def modpack():
cid = request.args.get("cid")
keys = request.args.get("k")
Expand All @@ -53,7 +53,7 @@ def modpack():
return jsonify({"modpacks": {modpack.slug: modpack.name for modpack in modpacks}, "mirror_url": public_repo_url})

@api.route("/api/modpack/<slug>")
@cached(cache_type(cache_size), key=lambda slug: str(request.args.get("cid")) + str(request.args.get('k')) + slug)
@cached(TTLCache(cache_size, cache_ttl), key=lambda slug: str(request.args.get("cid")) + str(request.args.get('k')) + slug)
def modpack_slug(slug: str):
cid = request.args.get("cid")
keys = request.args.get("k")
Expand All @@ -71,7 +71,7 @@ def modpack_slug(slug: str):
return jsonify({"error": "Modpack does not exist/Build does not exist"}), 404

@api.route("/api/modpack/<slugstring>/<buildstring>")
@cached(cache_type(cache_size), key=lambda slugstring, buildstring: str(request.args.get("cid")) + str(request.args.get("include")) + str(request.args.get("k")) + slugstring + buildstring)
@cached(TTLCache(cache_size, cache_ttl), key=lambda slugstring, buildstring: str(request.args.get("cid")) + str(request.args.get("include")) + str(request.args.get("k")) + slugstring + buildstring)
def modpack_slug_build(slugstring: str, buildstring: str):
keys = request.args.get("k")
key = Key.get_key(keys)
Expand Down Expand Up @@ -125,7 +125,7 @@ def mod():
return jsonify({"mods": {Mods.name: Mods.pretty_name for Mods in Mods}})

@api.route("/api/mod/<name>")
@cached(cache_type(cache_size), key=lambda name: name)
@cached(TTLCache(cache_size, cache_ttl), key=lambda name: name)
def mod_name(name: str):
mods = Mod.get_by_name_api(name)
if not mods:
Expand All @@ -137,7 +137,7 @@ def mod_name(name: str):
return jsonify(res)

@api.route("/api/mod/<name>/<version>")
@cached(cache_type(cache_size), key=lambda name, version: name + version)
@cached(TTLCache(cache_size, cache_ttl), key=lambda name, version: name + version)
def mod_name_version(name: str, version: str):
mod = Mod.get_by_name_api(name)
if not mod:
Expand Down
9 changes: 7 additions & 2 deletions models/common.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
from dotenv import load_dotenv
from cachetools import FIFOCache, LRUCache, LFUCache, RRCache

from models.database import Database

## Solderpy version
solderpy_version = "1.6.0"
solderpy_version = "1.6.1"

load_dotenv(".env")

Expand Down Expand Up @@ -80,6 +79,12 @@
print("No cache size specified, using default")
cache_size = int(100)

if (os.getenv("CACHE_TTL")):
cache_tool = int(os.getenv("CACHE_TTL"))
else:
print("No cache ttl specified, using default")
cache_tool = 300

class common:

@staticmethod
Expand Down

0 comments on commit bc20d97

Please sign in to comment.