cacheproxy-byiambaka-v2 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: cacheproxy-byiambaka-v2
3
+ Version: 0.1.0
4
+ Summary: A reverse proxy with redis cahing
5
+ Author: Aryan
6
+ License: MIT
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: fastapi>=0.115
10
+ Requires-Dist: uvicorn>=0.35
11
+ Requires-Dist: typer>=0.16
12
+ Requires-Dist: httpx>=0.28
13
+ Requires-Dist: redis>=6.2
14
+ Requires-Dist: pydantic>=2.11
15
+
16
+ Markdown
17
+
18
+ # cacheproxy ⚡
19
+
20
+ A high-performance command-line reverse proxy that automatically intercepts HTTP requests and caches them in Redis. Built with FastAPI, Typer, and Async Redis.
21
+
22
+
23
+
24
+ ## Features
25
+
26
+ * **Smart Caching:** Automatically caches safe `GET` 200 responses for 24 hours.
27
+ * **Header Optimization:** Seamlessly handles browser headers (strips encodings to prevent decoding bugs).
28
+ * **Binary Safe:** Uses `base64` encoding to store complex body types safely in Redis strings.
29
+ * **On-Demand Cache Purging:** Instantly flush the entire cache pool using the `/refresh` endpoint.
30
+ * **Flexible Configuration:** Fully configurable via Environment Variables or CLI arguments.
31
+
32
+ ## Installation
33
+
34
+ Install the utility directly via pip:
35
+
36
+ ```bash
37
+ pip install cacheproxy
38
+
39
+ How to Run
40
+ 1. Configure Redis (Optional)
41
+
42
+ The proxy automatically searches for a local Redis instance on port 6379. If your Redis instance lives elsewhere, pass the configuration using environment variables before running the tool:
43
+ Bash
44
+
45
+ # Linux/macOS
46
+ export REDDIS_HOST="127.0.0.1"
47
+ export REDIS_PORT="6379"
48
+ export REDDIS_DB="0"
49
+
50
+ # Windows (Command Prompt)
51
+ set REDDIS_HOST=127.0.0.1
52
+ set REDIS_PORT=6379
53
+ set REDDIS_DB=0
54
+
55
+ 2. Start the Proxy
56
+
57
+ Fire up the CLI command by pointing it to your destination origin API server:
58
+ Bash
59
+
60
+ cacheproxy start --origin [http://api.yourbackend.com](http://api.yourbackend.com) --port 3000
61
+
62
+ Now target your applications/frontend to run through http://localhost:3000.
63
+ API & Testing Endpoints
64
+ Checking Cache Status
65
+
66
+ When you run a request through the proxy, check your response headers to verify the status:
67
+
68
+ Cache: HIT - Served instantly out of Redis.
69
+
70
+ Cache: MISS - Fetched fresh from the origin server and saved for next time.
71
+
72
+ Flushing the Cache
73
+
74
+ If you update your backend data and want to wipe the proxy cache clean immediately, send a POST request to the refresh route:
75
+ Bash
76
+
77
+ curl -X POST http://localhost:3000/refresh
78
+
79
+ Response:
80
+ JSON
81
+
82
+ {"message": "cache cleared"}
83
+
84
+ License
85
+
86
+ MIT © 2026
@@ -0,0 +1,71 @@
1
+ Markdown
2
+
3
+ # cacheproxy ⚡
4
+
5
+ A high-performance command-line reverse proxy that automatically intercepts HTTP requests and caches them in Redis. Built with FastAPI, Typer, and Async Redis.
6
+
7
+
8
+
9
+ ## Features
10
+
11
+ * **Smart Caching:** Automatically caches safe `GET` 200 responses for 24 hours.
12
+ * **Header Optimization:** Seamlessly handles browser headers (strips encodings to prevent decoding bugs).
13
+ * **Binary Safe:** Uses `base64` encoding to store complex body types safely in Redis strings.
14
+ * **On-Demand Cache Purging:** Instantly flush the entire cache pool using the `/refresh` endpoint.
15
+ * **Flexible Configuration:** Fully configurable via Environment Variables or CLI arguments.
16
+
17
+ ## Installation
18
+
19
+ Install the utility directly via pip:
20
+
21
+ ```bash
22
+ pip install cacheproxy
23
+
24
+ How to Run
25
+ 1. Configure Redis (Optional)
26
+
27
+ The proxy automatically searches for a local Redis instance on port 6379. If your Redis instance lives elsewhere, pass the configuration using environment variables before running the tool:
28
+ Bash
29
+
30
+ # Linux/macOS
31
+ export REDDIS_HOST="127.0.0.1"
32
+ export REDIS_PORT="6379"
33
+ export REDDIS_DB="0"
34
+
35
+ # Windows (Command Prompt)
36
+ set REDDIS_HOST=127.0.0.1
37
+ set REDIS_PORT=6379
38
+ set REDDIS_DB=0
39
+
40
+ 2. Start the Proxy
41
+
42
+ Fire up the CLI command by pointing it to your destination origin API server:
43
+ Bash
44
+
45
+ cacheproxy start --origin [http://api.yourbackend.com](http://api.yourbackend.com) --port 3000
46
+
47
+ Now target your applications/frontend to run through http://localhost:3000.
48
+ API & Testing Endpoints
49
+ Checking Cache Status
50
+
51
+ When you run a request through the proxy, check your response headers to verify the status:
52
+
53
+ Cache: HIT - Served instantly out of Redis.
54
+
55
+ Cache: MISS - Fetched fresh from the origin server and saved for next time.
56
+
57
+ Flushing the Cache
58
+
59
+ If you update your backend data and want to wipe the proxy cache clean immediately, send a POST request to the refresh route:
60
+ Bash
61
+
62
+ curl -X POST http://localhost:3000/refresh
63
+
64
+ Response:
65
+ JSON
66
+
67
+ {"message": "cache cleared"}
68
+
69
+ License
70
+
71
+ MIT © 2026
File without changes
@@ -0,0 +1,77 @@
1
+ from fastapi import FastAPI,HTTPException,status
2
+ import httpx
3
+ import os
4
+ import redis.asyncio as redis
5
+ import json
6
+ import base64
7
+ from fastapi.responses import Response
8
+ from datetime import datetime
9
+ last_edit=0
10
+
11
+ app=FastAPI()
12
+ ORIGIN_URL=os.getenv("ORIGIN_URL")
13
+
14
+ redis_client= redis.Redis(host=os.getenv("REDIS_HOST", "localhost"),port=int(os.getenv("REDIS_PORT", 6379)),db=int(os.getenv("REDDIS_DB", 0)),decode_responses=True) #here decode is nessary otherwise i get byte objet
15
+
16
+ @app.get("/{path:path}",status_code=status.HTTP_200_OK)#here we use path to get values after main link
17
+ async def proxy_intercept(path:str):
18
+ if not ORIGIN_URL:
19
+ raise HTTPException(status_code=status.HTTP_404_NOT_FOUND,detail="URL dont found ")
20
+ target_url=f"{ORIGIN_URL}/{path}"
21
+ try:
22
+ cached_data=await redis_client.get(target_url)
23
+ if cached_data is not None:
24
+ cached_response=json.loads(cached_data) # convert json to python dict
25
+ body=base64.b64decode(cached_response["body"])#reddis cant store json
26
+ dict_header=dict(cached_response["headers"])
27
+ dict_header.pop("content-encoding", None) # browsee try to unzip on own thus to prevent
28
+ dict_header.pop("content-length", None)
29
+ dict_header.pop("transfer-encoding", None)
30
+
31
+ response=Response(
32
+ content=body,
33
+ status_code=cached_response["status_code"],
34
+ headers=dict_header
35
+ )
36
+ response.headers["Cache"]="HIT"
37
+
38
+ return response
39
+ except Exception as e:
40
+ print(f"Redis Error:{e}")
41
+
42
+
43
+
44
+ async with httpx.AsyncClient() as client:# if i dont use client each .get will create and destry thus waste
45
+ web_res = await client.get(target_url)
46
+ encode_body=base64.b64encode(web_res.content).decode('utf-8')
47
+ redis_value={
48
+ "status_code":web_res.status_code,
49
+ "headers": dict(web_res.headers),
50
+ "body":encode_body
51
+ }
52
+ if web_res.status_code == 200 and web_res.request.method=="GET":
53
+ try:
54
+ await redis_client.set(target_url,json.dumps(redis_value),ex=86400)#python object to json
55
+ global last_edit
56
+ last_edit = datetime.now().timestamp()
57
+
58
+ except Exception as e:
59
+ print(f"Redis save error:{e}")
60
+ output_header=dict(web_res.headers)
61
+ output_header.pop("content-encoding", None)
62
+ output_header.pop("content-length", None)
63
+ output_header.pop("transfer-encoding", None)
64
+ response = Response(
65
+ content=web_res.content,
66
+ status_code=web_res.status_code,
67
+ headers=output_header
68
+ )
69
+ response.headers["Cache"] = "MISS" # if it is already we chanced we already return a header of hit thus all will be not hit
70
+
71
+ return response
72
+ @app.post("/refresh",status_code=status.HTTP_200_OK)
73
+ async def refresh_cache():
74
+ await redis_client.flushdb()
75
+ return {"message":"cache cleared"}
76
+
77
+
@@ -0,0 +1,25 @@
1
+ import typer
2
+ import os
3
+ import uvicorn
4
+ from pydantic import ValidationError
5
+ from cacheproxy.cli.cli_verification import CLIValidation
6
+ app=typer.Typer()
7
+ @app.command()
8
+ def start(port:int=typer.Option(3000,"--port",help="port on which you want to run "),origin:str=typer.Option(...,"--origin",help="the url you want to cache ")):# used in context as first thing it can be start etc anything
9
+ try:
10
+ config=CLIValidation(
11
+ port=port,
12
+ origin=origin,
13
+ )
14
+ except ValidationError as e:
15
+ typer.echo(e)
16
+ raise typer.Exit(code=1)
17
+ typer.echo("The Server Is Successfully Started \n The Server Is Hosted At :-")
18
+ typer.echo(f"http://localhost:{port}")
19
+
20
+ os.environ["ORIGIN_URL"]=str(config.origin)
21
+ os.environ["PORT"]=str(config.port)
22
+ uvicorn.run("cacheproxy.app.main:app",host="0.0.0.0",port=config.port,)#can run in any network
23
+
24
+ if __name__=="__main__":
25
+ app()# it will not auto run even fastapi need uvicorn and python auto craeted __name__="__main__"
@@ -0,0 +1,6 @@
1
+ from pydantic import BaseModel, HttpUrl,Field
2
+ class CLIValidation(BaseModel):
3
+ port: int = Field(3000,ge=1,le=65535)#maximum port is 16 bit
4
+ origin: HttpUrl
5
+
6
+
@@ -0,0 +1,86 @@
1
+ Metadata-Version: 2.4
2
+ Name: cacheproxy-byiambaka-v2
3
+ Version: 0.1.0
4
+ Summary: A reverse proxy with redis cahing
5
+ Author: Aryan
6
+ License: MIT
7
+ Requires-Python: >=3.11
8
+ Description-Content-Type: text/markdown
9
+ Requires-Dist: fastapi>=0.115
10
+ Requires-Dist: uvicorn>=0.35
11
+ Requires-Dist: typer>=0.16
12
+ Requires-Dist: httpx>=0.28
13
+ Requires-Dist: redis>=6.2
14
+ Requires-Dist: pydantic>=2.11
15
+
16
+ Markdown
17
+
18
+ # cacheproxy ⚡
19
+
20
+ A high-performance command-line reverse proxy that automatically intercepts HTTP requests and caches them in Redis. Built with FastAPI, Typer, and Async Redis.
21
+
22
+
23
+
24
+ ## Features
25
+
26
+ * **Smart Caching:** Automatically caches safe `GET` 200 responses for 24 hours.
27
+ * **Header Optimization:** Seamlessly handles browser headers (strips encodings to prevent decoding bugs).
28
+ * **Binary Safe:** Uses `base64` encoding to store complex body types safely in Redis strings.
29
+ * **On-Demand Cache Purging:** Instantly flush the entire cache pool using the `/refresh` endpoint.
30
+ * **Flexible Configuration:** Fully configurable via Environment Variables or CLI arguments.
31
+
32
+ ## Installation
33
+
34
+ Install the utility directly via pip:
35
+
36
+ ```bash
37
+ pip install cacheproxy
38
+
39
+ How to Run
40
+ 1. Configure Redis (Optional)
41
+
42
+ The proxy automatically searches for a local Redis instance on port 6379. If your Redis instance lives elsewhere, pass the configuration using environment variables before running the tool:
43
+ Bash
44
+
45
+ # Linux/macOS
46
+ export REDDIS_HOST="127.0.0.1"
47
+ export REDIS_PORT="6379"
48
+ export REDDIS_DB="0"
49
+
50
+ # Windows (Command Prompt)
51
+ set REDDIS_HOST=127.0.0.1
52
+ set REDIS_PORT=6379
53
+ set REDDIS_DB=0
54
+
55
+ 2. Start the Proxy
56
+
57
+ Fire up the CLI command by pointing it to your destination origin API server:
58
+ Bash
59
+
60
+ cacheproxy start --origin [http://api.yourbackend.com](http://api.yourbackend.com) --port 3000
61
+
62
+ Now target your applications/frontend to run through http://localhost:3000.
63
+ API & Testing Endpoints
64
+ Checking Cache Status
65
+
66
+ When you run a request through the proxy, check your response headers to verify the status:
67
+
68
+ Cache: HIT - Served instantly out of Redis.
69
+
70
+ Cache: MISS - Fetched fresh from the origin server and saved for next time.
71
+
72
+ Flushing the Cache
73
+
74
+ If you update your backend data and want to wipe the proxy cache clean immediately, send a POST request to the refresh route:
75
+ Bash
76
+
77
+ curl -X POST http://localhost:3000/refresh
78
+
79
+ Response:
80
+ JSON
81
+
82
+ {"message": "cache cleared"}
83
+
84
+ License
85
+
86
+ MIT © 2026
@@ -0,0 +1,14 @@
1
+ README.md
2
+ pyproject.toml
3
+ cacheproxy/__init__.py
4
+ cacheproxy/app/__init__.py
5
+ cacheproxy/app/main.py
6
+ cacheproxy/cli/__init__.py
7
+ cacheproxy/cli/cli_input.py
8
+ cacheproxy/cli/cli_verification.py
9
+ cacheproxy_byiambaka_v2.egg-info/PKG-INFO
10
+ cacheproxy_byiambaka_v2.egg-info/SOURCES.txt
11
+ cacheproxy_byiambaka_v2.egg-info/dependency_links.txt
12
+ cacheproxy_byiambaka_v2.egg-info/entry_points.txt
13
+ cacheproxy_byiambaka_v2.egg-info/requires.txt
14
+ cacheproxy_byiambaka_v2.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ cacheproxy = cacheproxy.cli.cli_input:app
@@ -0,0 +1,6 @@
1
+ fastapi>=0.115
2
+ uvicorn>=0.35
3
+ typer>=0.16
4
+ httpx>=0.28
5
+ redis>=6.2
6
+ pydantic>=2.11
@@ -0,0 +1,28 @@
1
+ [build-system]
2
+ requires=["setuptools>=68","wheel"]
3
+ build-backend="setuptools.build_meta" #these files help me to create my project exceture for other
4
+ [project]
5
+ name="cacheproxy-byiambaka-v2"
6
+ version="0.1.0"
7
+ description="A reverse proxy with redis cahing"
8
+ readme="README.md"
9
+ requires-python=">=3.11"
10
+ license={ text = "MIT" } # we create dict thus add morem licence if want
11
+ authors=[
12
+ {name="Aryan"}
13
+ ]
14
+ dependencies=[
15
+ "fastapi>=0.115",
16
+ "uvicorn>=0.35",
17
+ "typer>=0.16",
18
+ "httpx>=0.28",
19
+ "redis>=6.2",
20
+ "pydantic>=2.11"
21
+ ]
22
+ [project.scripts]
23
+ cacheproxy="cacheproxy.cli.cli_input:app"
24
+ [tool.setuptools.packages.find]
25
+ where = ["."] #find this src folder serch files in current directory
26
+
27
+
28
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+