Skip to content

Commit

Permalink
⬆️ Reput realtime caching + upgrade to erpc:0.0.35
Browse files Browse the repository at this point in the history
  • Loading branch information
KONFeature committed Jan 3, 2025
1 parent 5c51764 commit def39f2
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 55 deletions.
7 changes: 5 additions & 2 deletions infra/erpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,11 @@ export const erpcService = new SstService("Erpc", {
},
// Container health check
health: {
command: ["CMD-SHELL", "curl -f http://localhost:8080/healthcheck || exit 1"],
startPeriod: "15 seconds"
command: [
"CMD-SHELL",
"curl -f http://localhost:8080/healthcheck || exit 1",
],
startPeriod: "15 seconds",
},
// Logging options
logging: {
Expand Down
12 changes: 6 additions & 6 deletions packages/erpc/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Config bundler step
FROM oven/bun:latest AS bundler
RUN mkdir -p /temp/dev
RUN mkdir -p /tmp/dev

# Bundle everything in a single erpc.js file
COPY . /temp/dev
RUN cd /temp/dev && bun install --production
RUN cd /temp/dev && bun build --outfile ./erpc.js --minify --target node --external "@erpc-cloud/*" src/index.ts
COPY . /tmp/dev
RUN cd /tmp/dev && bun install --production
RUN cd /tmp/dev && bun build --outfile ./erpc.js --minify --target node --external "@erpc-cloud/*" src/index.ts

# Final image
#FROM erpc-dev AS final
FROM ghcr.io/erpc/erpc@sha256:c2e09378e5b7922428e8363c577fdf063aaf3d060e79ce44f8f9006c47bc80f6 AS final
FROM ghcr.io/erpc/erpc:0.0.35 AS final

# Install curl, will be used for healthcheck
RUN apt-get update && apt-get install -y curl

# Copy the bundled config
COPY --from=bundler ./temp/dev/erpc.js /root/erpc.js
COPY --from=bundler ./tmp/dev/erpc.js /root/erpc.js

# Run the server
CMD ["./erpc-server"]
97 changes: 50 additions & 47 deletions packages/erpc/src/storage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import {
type CacheConfig,
CacheEmptyBehaviorAllow,
CacheEmptyBehaviorIgnore,
type CachePolicyConfig,
type ConnectorConfig,
DataFinalityStateFinalized,
DataFinalityStateRealtime,
DataFinalityStateUnfinalized,
} from "@erpc-cloud/config";

if (!process.env.ERPC_DATABASE_URL) {
Expand All @@ -22,22 +25,22 @@ const connectors = [
table: "rpc_cache",
},
},
// {
// id: "memory-unfinalized",
// driver: "memory",
// memory: {
// // max 4k items for unfinalized cache
// maxItems: 4_096,
// },
// },
// {
// id: "memory-realtime",
// driver: "memory",
// memory: {
// // Max 4k items for realtime cache
// maxItems: 4_096,
// },
// },
{
id: "memory-unfinalized",
driver: "memory",
memory: {
// max 4k items for unfinalized cache
maxItems: 4_096,
},
},
{
id: "memory-realtime",
driver: "memory",
memory: {
// Max 4k items for realtime cache
maxItems: 4_096,
},
},
] as const satisfies ConnectorConfig[];

/**
Expand All @@ -54,37 +57,37 @@ const cachePolicies = [
finality: DataFinalityStateFinalized,
empty: CacheEmptyBehaviorAllow,
},
// // Cache not finalized data for 2sec in the memory
// {
// connector: "memory-unfinalized",
// network: "*",
// method: "*",
// finality: DataFinalityStateUnfinalized,
// empty: CacheEmptyBehaviorIgnore,
// // 2sec in nanoseconds
// ttl: 2_000_000_000,
// maxItemSize: "20kb",
// },
// // Cache realtime data for 2sec on the memory on arbitrum
// {
// connector: "memory-realtime",
// network: "evm:42161",
// method: "*",
// finality: DataFinalityStateRealtime,
// empty: CacheEmptyBehaviorIgnore,
// // 2sec in nanoseconds
// ttl: 2_000_000_000,
// },
// // Cache realtime data for 30sec on arbitrum sepolia
// {
// connector: "memory-realtime",
// network: "evm:421614",
// method: "*",
// finality: DataFinalityStateRealtime,
// empty: CacheEmptyBehaviorIgnore,
// // 30sec in nanoseconds
// ttl: 30_000_000_000,
// },
// Cache not finalized data for 2sec in the memory
{
connector: "memory-unfinalized",
network: "*",
method: "*",
finality: DataFinalityStateUnfinalized,
empty: CacheEmptyBehaviorIgnore,
// 2sec in nanoseconds
ttl: 2_000_000_000,
maxItemSize: "20kb",
},
// Cache realtime data for 2sec on the memory on arbitrum
{
connector: "memory-realtime",
network: "evm:42161",
method: "*",
finality: DataFinalityStateRealtime,
empty: CacheEmptyBehaviorIgnore,
// 2sec in nanoseconds
ttl: 2_000_000_000,
},
// Cache realtime data for 30sec on arbitrum sepolia
{
connector: "memory-realtime",
network: "evm:421614",
method: "*",
finality: DataFinalityStateRealtime,
empty: CacheEmptyBehaviorIgnore,
// 30sec in nanoseconds
ttl: 30_000_000_000,
},
] as const satisfies CachePolicyConfig[];

/**
Expand Down

0 comments on commit def39f2

Please sign in to comment.