Merge remote-tracking branch 'origin/master'

This commit is contained in:
Sky
2016-04-22 15:31:42 +08:00
2 changed files with 25 additions and 4 deletions

View File

@@ -1,10 +1,13 @@
# iBlog2
基于 Node.js 的个人开源博客系统,采用响应式布局,支持电脑、手机等直接访问,简单实用,美观大方。
(基于 ASP.NET 的 iBlog 点击[这里](https://github.com/eshengsky/iBlog/)
基于 Node.js 的个人开源博客系统,采用响应式布局,支持移动设备直接访问,功能全面,美观大方。
(基于 ASP.NET 的版本请点击[这里](https://github.com/eshengsky/iBlog/)
## 在线实例
个人博客 [http://www.skysun.name/](http://www.skysun.name/)
## [Wiki](https://github.com/eshengsky/iBlog2/wiki)
该 Wiki 汇总了 iBlog2 中涉及 Node.js 及部分前端技术的基本功能与知识点,适合新手学习、备查。
## 功能模块
#### 博客
* 文章列表页
@@ -67,9 +70,19 @@ $ bower install
```
在 "后台管理-系统设置" 页面中,支持以可视化方式配置其余参数。
#### 启动站点
* 方式1普通模式启动
```Shell
$ node --harmony-proxies ./bin/www
```
* 方式2快速启动
```Shell
$ npm start
```
* 方式3守护进程启动
_守护进程能够发挥多核CPU性能并在出现异常退出后延迟30秒自动重启工作进程。_
```Shell
$ node --harmony-proxies daemon.js
```
打开浏览器,访问 [http://localhost:3000/](http://localhost:3000)
#### Enjoy it! :smile:
@@ -77,7 +90,7 @@ $ node --harmony-proxies ./bin/www
文章分类、文章列表、文章详细等都作了缓存处理,若想使修改立即可见,需要在"后台管理-缓存管理"页面手动清除缓存。
## 线上部署
推荐使用[pm2](https://github.com/Unitech/pm2)进行线上Node.js的进程管理和持久运行。
推荐使用 [pm2](https://github.com/Unitech/pm2) 进行线上Node.js的进程管理和持久运行。
#### 安装
```Shell
$ npm install -g pm2

View File

@@ -34,16 +34,22 @@ exports.getAll = function (isAll, cached, callback) {
isAll = true;
cached = true;
}
//缓存的key名称
var cache_key = isAll ? 'categories_all' : 'categories';
if (cached) {
//尝试读取缓存
redisClient.getItem(cache_key, function (err, categories) {
//读取缓存出错
if (err) {
return callback(err);
}
//缓存中有数据
if (categories) {
return callback(null, categories);
}
//缓存中没有数据,则从数据库中读取
categoryModel.find(function (err, categories) {
//读取数据库出错
if (err) {
return callback(err);
}
@@ -51,7 +57,9 @@ exports.getAll = function (isAll, cached, callback) {
categories.unshift(cateAll);
categories.push(cateOther);
}
//从数据库中读到数据
if (categories) {
//将数据塞入缓存
redisClient.setItem(cache_key, categories, redisClient.defaultExpired, function (err) {
if (err) {
return callback(err);
@@ -190,4 +198,4 @@ exports.save = function (array, callback) {
}
});
});
};
};