Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
renovate
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GitHub Mirror
Renovate Bot
renovate
Commits
1e702c2a
Unverified
Commit
1e702c2a
authored
1 month ago
by
Sergei Zharinov
Committed by
GitHub
1 month ago
Browse files
Options
Downloads
Patches
Plain Diff
feat(http): Create memory cache provider (#33900)
parent
b5ae2f59
No related branches found
Branches containing commit
Tags
39.165.0
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/util/http/cache/memory-http-cache-provider.spec.ts
+39
-0
39 additions, 0 deletions
lib/util/http/cache/memory-http-cache-provider.spec.ts
lib/util/http/cache/memory-http-cache-provider.ts
+21
-0
21 additions, 0 deletions
lib/util/http/cache/memory-http-cache-provider.ts
with
60 additions
and
0 deletions
lib/util/http/cache/memory-http-cache-provider.spec.ts
0 → 100644
+
39
−
0
View file @
1e702c2a
import
{
Http
}
from
'
..
'
;
import
*
as
httpMock
from
'
../../../../test/http-mock
'
;
import
*
as
memCache
from
'
../../cache/memory
'
;
import
{
memCacheProvider
as
cacheProvider
}
from
'
./memory-http-cache-provider
'
;
describe
(
'
util/http/cache/memory-http-cache-provider
'
,
()
=>
{
beforeEach
(()
=>
{
memCache
.
init
();
});
afterEach
(()
=>
{
memCache
.
reset
();
});
const
http
=
new
Http
(
'
test
'
);
it
(
'
reuses data with etag
'
,
async
()
=>
{
const
scope
=
httpMock
.
scope
(
'
https://example.com
'
);
scope
.
get
(
'
/foo/bar
'
).
reply
(
200
,
{
msg
:
'
Hello, world!
'
},
{
etag
:
'
123
'
});
const
res1
=
await
http
.
getJsonUnchecked
(
'
https://example.com/foo/bar
'
,
{
cacheProvider
,
});
expect
(
res1
).
toMatchObject
({
statusCode
:
200
,
body
:
{
msg
:
'
Hello, world!
'
},
authorization
:
false
,
});
const
res2
=
await
http
.
getJsonUnchecked
(
'
https://example.com/foo/bar
'
,
{
cacheProvider
,
});
expect
(
res2
).
toMatchObject
({
statusCode
:
200
,
body
:
{
msg
:
'
Hello, world!
'
},
authorization
:
false
,
});
});
});
This diff is collapsed.
Click to expand it.
lib/util/http/cache/memory-http-cache-provider.ts
0 → 100644
+
21
−
0
View file @
1e702c2a
import
*
as
memCache
from
'
../../cache/memory
'
;
import
{
AbstractHttpCacheProvider
}
from
'
./abstract-http-cache-provider
'
;
import
type
{
HttpCache
}
from
'
./schema
'
;
export
class
MemoryHttpCacheProvider
extends
AbstractHttpCacheProvider
{
private
cacheKey
(
url
:
string
):
string
{
return
`memory-cache-http-provider:
${
url
}
`
;
}
protected
override
load
(
url
:
string
):
Promise
<
unknown
>
{
const
data
=
memCache
.
get
<
HttpCache
>
(
this
.
cacheKey
(
url
));
return
Promise
.
resolve
(
data
);
}
protected
override
persist
(
url
:
string
,
data
:
HttpCache
):
Promise
<
void
>
{
memCache
.
set
(
this
.
cacheKey
(
url
),
data
);
return
Promise
.
resolve
();
}
}
export
const
memCacheProvider
=
new
MemoryHttpCacheProvider
();
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment