Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable caching #19

Merged
merged 2 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Added a launcher function `launch` to make it easier to launch the app.
- Semantic caching enabled by SemanticCaches.jl. You can change it by setting `cached=false` in the `launch()` function (minimum similarity for cache hit is 0.99).
- Semantic caching provided by SemanticCaches.jl. You can change it by setting `cached=false` in the `launch()` function. It's disabled by default.

### Fixed
- Fixed a bug when caching would error for certain types of HTTP body (eg, `IOBuffer`)
Expand Down
2 changes: 1 addition & 1 deletion main.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ Pkg.activate(".")
## Required to support semantic caching
ENV["DATADEPS_ALWAYS_ACCEPT"] = "true"
using ProToPortal
ProToPortal.launch(8000, "0.0.0.0"; async = false, cached = true, cache_verbose = true)
ProToPortal.launch(8000, "0.0.0.0"; async = false, cached = false, cache_verbose = false)
9 changes: 5 additions & 4 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
launch(
port::Int = get(ENV, "PORT", 8000), host::String = get(
ENV, "GENIE_HOST", "127.0.0.1");
async::Bool = true, cached::Bool = true, cache_verbose::Bool = false)
async::Bool = true, cached::Bool = false, cache_verbose::Bool = false)

Launches ProToPortal in the browser.

Expand All @@ -13,20 +13,21 @@ This is a convenience wrapper around `Genie.up`, to customize the server configu
- `port::Union{Int, String} = get(ENV, "PORT", "8000")`: The port to launch the server on.
- `host::String = get(ENV, "GENIE_HOST", "127.0.0.1")`: The host to launch the server on.
- `async::Bool = true`: Whether to launch the server asynchronously, ie, in the background.
- `cached::Bool = true`: Whether to use semantic caching of the requests.
- `cache_verbose::Bool = true`: Whether to print verbose information about the caching process.
- `cached::Bool = false`: Whether to use semantic caching of the requests.
- `cache_verbose::Bool = false`: Whether to print verbose information about the caching process.

If you want to remove the cache layer later, you can use `import HTTP; HTTP.poplayer!()`.
"""
function launch(
port::Union{Int, String} = get(ENV, "PORT", "8000"),
host::String = get(ENV, "GENIE_HOST", "127.0.0.1");
async::Bool = true, cached::Bool = true, cache_verbose::Bool = true)
async::Bool = true, cached::Bool = false, cache_verbose::Bool = false)
## Loads app.jl in the root directory
Genie.loadapp(pkgdir(ProToPortal))

## Enables caching
ENV["CACHES_VERBOSE"] = cache_verbose ? "true" : "false"
## disable until we can do length-adjusted semantic distance
if cached
@info "Caching enabled globally (for all requests, see `CacheLayer` module for details). Remove with `HTTP.poplayer!()`"
HTTP.pushlayer!(CacheLayer.cache_layer)
Expand Down
Loading