Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
openbis
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
sispub
openbis
Commits
09992f44
Commit
09992f44
authored
14 years ago
by
buczekp
Browse files
Options
Downloads
Patches
Plain Diff
[LMS-1492] configured caching
SVN: 15523
parent
cc5d92b5
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
openbis/resource/server/web.xml
+9
-0
9 additions, 0 deletions
openbis/resource/server/web.xml
openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CacheFilter.java
+78
-0
78 additions, 0 deletions
.../ch/systemsx/cisd/openbis/generic/server/CacheFilter.java
with
87 additions
and
0 deletions
openbis/resource/server/web.xml
+
9
−
0
View file @
09992f44
...
...
@@ -36,6 +36,15 @@
ch.systemsx.cisd.openbis.generic.server.GenericHttpSessionListener
</listener-class>
</listener>
<filter>
<filter-name>
CacheFilter
</filter-name>
<filter-class>
ch.systemsx.cisd.openbis.generic.server.CacheFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>
CacheFilter
</filter-name>
<url-pattern>
/*
</url-pattern>
</filter-mapping>
<!-- Trying kind of extension (i.e., '*.do') here as 'url-pattern' does not work. -->
<servlet-mapping>
...
...
This diff is collapsed.
Click to expand it.
openbis/source/java/ch/systemsx/cisd/openbis/generic/server/CacheFilter.java
0 → 100644
+
78
−
0
View file @
09992f44
/*
* Copyright 2008 ETH Zuerich, CISD
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
ch.systemsx.cisd.openbis.generic.server
;
import
java.io.IOException
;
import
javax.servlet.Filter
;
import
javax.servlet.FilterChain
;
import
javax.servlet.FilterConfig
;
import
javax.servlet.ServletException
;
import
javax.servlet.ServletRequest
;
import
javax.servlet.ServletResponse
;
import
javax.servlet.http.HttpServletRequest
;
import
javax.servlet.http.HttpServletResponse
;
/**
* Implements {@link Filter} and sets the cache to store data for resources that don't have
* '.nocache.' in their name. Static resources such as images should stay in cache for a long time.
*
* @author Piotr Buczek
*/
public
class
CacheFilter
implements
Filter
{
@SuppressWarnings
(
"unused"
)
private
FilterConfig
filterConfig
;
private
static
final
int
DAY_IN_SECONDS
=
24
*
60
*
60
;
private
static
final
int
YEAR_IN_SECONDS
=
365
*
DAY_IN_SECONDS
;
private
static
final
int
SPRINT_IN_SECONDS
=
14
*
DAY_IN_SECONDS
;
public
void
doFilter
(
ServletRequest
request
,
ServletResponse
response
,
FilterChain
filterChain
)
throws
IOException
,
ServletException
{
HttpServletRequest
httpRequest
=
(
HttpServletRequest
)
request
;
String
requestURI
=
httpRequest
.
getRequestURI
();
if
(
requestURI
.
contains
(
".nocache."
)
==
false
)
{
HttpServletResponse
httpResponse
=
(
HttpServletResponse
)
response
;
httpResponse
.
addHeader
(
"Cache-Control"
,
"max-age="
+
(
isPicture
(
requestURI
)
?
YEAR_IN_SECONDS
:
SPRINT_IN_SECONDS
));
}
filterChain
.
doFilter
(
request
,
response
);
}
private
boolean
isPicture
(
String
requestURI
)
{
return
requestURI
.
endsWith
(
".gif"
)
||
requestURI
.
endsWith
(
".png"
);
}
public
void
init
(
FilterConfig
config
)
throws
ServletException
{
this
.
filterConfig
=
config
;
}
public
void
destroy
()
{
this
.
filterConfig
=
null
;
}
}
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