Skip to content

Commit c44c0b7

Browse files
committed
feat: add -d:disableCachedRoutes argument
1 parent 8719f56 commit c44c0b7

File tree

3 files changed

+28
-25
lines changed

3 files changed

+28
-25
lines changed

happyx.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
description = "Macro-oriented asynchronous web-framework written with ♥"
44
author = "HapticX"
5-
version = "4.6.5"
5+
version = "4.7.0"
66
license = "MIT"
77
srcDir = "src"
88
installExt = @["nim"]

src/happyx/core/constants.nim

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const
5656
enableUseCompDebugMacro* = defined(useCompDebug) or defined(happyxUseCompDebug) or defined(hpxUseCompDebug)
5757
enableRequestModelDebugMacro* = defined(reqModelDebug) or defined(happyxReqModelDebug) or defined(hpxReqModelDebug)
5858
enableRoutingDebugMacro* = defined(routingDebug) or defined(happyxRoutingDebug) or defined(hpxRoutingDebug)
59-
enableDefaultDecorators* = not (defined(disableDefDeco) or defined(happyxDsableDefDeco) or defined(hpxDisableDefDeco))
59+
enableDefaultDecorators* = not (defined(disableDefDeco) or defined(happyxDisableDefDeco) or defined(hpxDisableDefDeco))
60+
enableCachedRoutes* = not (defined(disableCachedRoutes) or defined(happyxDisableCachedRoutes) or defined(hpxDisabledCachedRoutes))
6061
enableDefaultComponents* = not (defined(disableComp) or defined(happyxDisableComp) or defined(hpxDisableComp))
6162
enableAppRouting* = not (defined(disableRouting) or defined(happyxDisableRouting) or defined(hpxDisableRouting))
6263
enableTemplateEngine* = not (defined(disableTemplateEngine) or defined(happyxTemplateEngine) or defined(hpxTemplateEngine))
@@ -108,8 +109,8 @@ const
108109
nim_2_0_0* = (NimMajor, NimMinor, NimPatch) >= (2, 0, 0)
109110
# Framework version
110111
HpxMajor* = 4
111-
HpxMinor* = 6
112-
HpxPatch* = 5
112+
HpxMinor* = 7
113+
HpxPatch* = 0
113114
HpxVersion* = $HpxMajor & "." & $HpxMinor & "." & $HpxPatch
114115

115116

src/happyx/ssr/server.nim

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,20 @@ template answer*(
290290
h[key] = val
291291

292292
# Cache result
293-
when declared(thisRouteCanBeCached) and declared(routeKey) and not declared(thisIsCachedResponse):
294-
cachedRoutes[routeKey] = CachedRoute(create_at: cpuTime())
295-
when message is string:
296-
cachedRoutes[routeKey].res = CachedResult(data: message)
297-
else:
298-
cachedRoutes[routeKey].res = CachedResult(data: $message)
299-
cachedRoutes[routeKey].res.statusCode = code
300-
when useHeaders:
301-
cachedRoutes[routeKey].res.headers = h
302-
else:
303-
cachedRoutes[routeKey].res.headers = newHttpHeaders([
304-
("Content-Type", "text/plain;charset=utf-8")
305-
])
293+
when enableCachedRoutes:
294+
when declared(thisRouteCanBeCached) and declared(routeKey) and not declared(thisIsCachedResponse):
295+
cachedRoutes[routeKey] = CachedRoute(create_at: cpuTime())
296+
when message is string:
297+
cachedRoutes[routeKey].res = CachedResult(data: message)
298+
else:
299+
cachedRoutes[routeKey].res = CachedResult(data: $message)
300+
cachedRoutes[routeKey].res.statusCode = code
301+
when useHeaders:
302+
cachedRoutes[routeKey].res.headers = h
303+
else:
304+
cachedRoutes[routeKey].res.headers = newHttpHeaders([
305+
("Content-Type", "text/plain;charset=utf-8")
306+
])
306307

307308
# HTTPX
308309
when enableHttpx or enableBuiltin:
@@ -415,14 +416,15 @@ template answer*(
415416
h[key] = val
416417

417418
# Cache result
418-
when declared(thisRouteCanBeCached) and declared(routeKey) and not declared(thisIsCachedResponse):
419-
cachedRoutes[routeKey] = CachedRoute(create_at: cpuTime())
420-
when message is string:
421-
cachedRoutes[routeKey].res = CachedResult(data: message)
422-
else:
423-
cachedRoutes[routeKey].res = CachedResult(data: $message)
424-
cachedRoutes[routeKey].res.statusCode = code
425-
cachedRoutes[routeKey].res.headers = h
419+
when enableCachedRoutes:
420+
when declared(thisRouteCanBeCached) and declared(routeKey) and not declared(thisIsCachedResponse):
421+
cachedRoutes[routeKey] = CachedRoute(create_at: cpuTime())
422+
when message is string:
423+
cachedRoutes[routeKey].res = CachedResult(data: message)
424+
else:
425+
cachedRoutes[routeKey].res = CachedResult(data: $message)
426+
cachedRoutes[routeKey].res.statusCode = code
427+
cachedRoutes[routeKey].res.headers = h
426428

427429
# HTTPX
428430
when enableHttpx or enableBuiltin:

0 commit comments

Comments
 (0)