Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
solo-1
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
solo-1
Commits
6bcd7fe9
Commit
6bcd7fe9
authored
Aug 30, 2017
by
Liang Ding
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
⚡
#12319 缓存统计数据
parent
51c850f2
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
121 additions
and
3 deletions
+121
-3
src/main/java/org/b3log/solo/cache/StatisticCache.java
src/main/java/org/b3log/solo/cache/StatisticCache.java
+77
-0
src/main/java/org/b3log/solo/repository/impl/StatisticRepositoryImpl.java
...g/b3log/solo/repository/impl/StatisticRepositoryImpl.java
+44
-3
No files found.
src/main/java/org/b3log/solo/cache/StatisticCache.java
0 → 100644
View file @
6bcd7fe9
/*
* Copyright (c) 2010-2017, b3log.org & hacpai.com
*
* 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
org
.
b3log
.
solo
.
cache
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.cache.Cache
;
import
org.b3log.latke.cache.CacheFactory
;
import
org.b3log.latke.ioc.inject.Named
;
import
org.b3log.latke.ioc.inject.Singleton
;
import
org.b3log.solo.model.Statistic
;
import
org.b3log.solo.util.JSONs
;
import
org.json.JSONObject
;
/**
* Statistic cache.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Aug 30, 2017
* @since 2.3.0
*/
@Named
@Singleton
public
class
StatisticCache
{
/**
* Statistic cache.
*/
private
Cache
cache
=
CacheFactory
.
getCache
(
Statistic
.
STATISTIC
);
/**
* Gets an statistic by the specified statistic id.
*
* @param id the specified statistic id
* @return statistic, returns {@code null} if not found
*/
public
JSONObject
getStatistic
(
final
String
id
)
{
final
JSONObject
statistic
=
cache
.
get
(
id
);
if
(
null
==
statistic
)
{
return
null
;
}
return
JSONs
.
clone
(
statistic
);
}
/**
* Adds or updates the specified statistic.
*
* @param statistic the specified statistic
*/
public
void
putStatistic
(
final
JSONObject
statistic
)
{
final
String
statisticId
=
statistic
.
optString
(
Keys
.
OBJECT_ID
);
cache
.
put
(
statisticId
,
JSONs
.
clone
(
statistic
));
}
/**
* Removes an statistic by the specified statistic id.
*
* @param id the specified statistic id
*/
public
void
removeStatistic
(
final
String
id
)
{
cache
.
remove
(
id
);
}
}
src/main/java/org/b3log/solo/repository/impl/StatisticRepositoryImpl.java
View file @
6bcd7fe9
...
...
@@ -15,18 +15,21 @@
*/
package
org
.
b3log
.
solo
.
repository
.
impl
;
import
org.b3log.latke.Keys
;
import
org.b3log.latke.ioc.inject.Inject
;
import
org.b3log.latke.repository.AbstractRepository
;
import
org.b3log.latke.repository.RepositoryException
;
import
org.b3log.latke.repository.annotation.Repository
;
import
org.b3log.solo.cache.StatisticCache
;
import
org.b3log.solo.model.Statistic
;
import
org.b3log.solo.repository.StatisticRepository
;
import
org.json.JSONObject
;
/**
* Statistic repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.
0.0.2, May 15, 2013
* @version 1.
1.0.0, Aug 30, 2017
* @since 0.3.1
*/
@Repository
...
...
@@ -38,4 +41,42 @@ public class StatisticRepositoryImpl extends AbstractRepository implements Stati
public
StatisticRepositoryImpl
()
{
super
(
Statistic
.
STATISTIC
);
}
/**
* Statistic cache.
*/
@Inject
private
StatisticCache
statisticCache
;
@Override
public
void
remove
(
final
String
id
)
throws
RepositoryException
{
super
.
remove
(
id
);
statisticCache
.
removeStatistic
(
id
);
}
@Override
public
JSONObject
get
(
final
String
id
)
throws
RepositoryException
{
JSONObject
ret
=
statisticCache
.
getStatistic
(
id
);
if
(
null
!=
ret
)
{
return
ret
;
}
ret
=
super
.
get
(
id
);
if
(
null
==
ret
)
{
return
null
;
}
statisticCache
.
putStatistic
(
ret
);
return
ret
;
}
@Override
public
void
update
(
final
String
id
,
final
JSONObject
statistic
)
throws
RepositoryException
{
super
.
update
(
id
,
statistic
);
statistic
.
put
(
Keys
.
OBJECT_ID
,
id
);
statisticCache
.
putStatistic
(
statistic
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment