| 64 | } |
| 65 | |
| 66 | bool session::flush(void) |
| 67 | { |
| 68 | if (!dirty_) { |
| 69 | return true; |
| 70 | } |
| 71 | dirty_ = false; |
| 72 | |
| 73 | // ���ô���ӿڣ����ԭ���� sid ���� |
| 74 | if (get_attrs(attrs_)) { |
| 75 | if (!sid_saved_) { |
| 76 | sid_saved_ = true; |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | std::map<string, session_string>::iterator it_cache = |
| 81 | attrs_cache_.begin(); |
| 82 | for (; it_cache != attrs_cache_.end(); ++it_cache) { |
| 83 | // ����������Ѵ��ڣ�����Ҫ���ͷ�ԭ��������ֵ����������ֵ |
| 84 | |
| 85 | std::map<string, session_string>::iterator it_attr = |
| 86 | attrs_.find(it_cache->first); |
| 87 | if (it_attr == attrs_.end()) { |
| 88 | if (it_cache->second.todo_ == TODO_SET) { |
| 89 | attrs_.insert(std::make_pair(it_cache->first, |
| 90 | it_cache->second)); |
| 91 | } |
| 92 | } else if (it_cache->second.todo_ == TODO_SET) { |
| 93 | // �����µ����� |
| 94 | attrs_.insert(std::make_pair(it_cache->first, |
| 95 | it_cache->second)); |
| 96 | } else if (it_cache->second.todo_ == TODO_DEL) { |
| 97 | attrs_.erase(it_attr); |
| 98 | } else { |
| 99 | logger_warn("unknown todo(%d)", |
| 100 | (int) it_cache->second.todo_); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // �����������ݣ���Ϊ�ڲ��������Ѿ��������� attrs_ �У� |
| 105 | // ����ֻ��Ҫ�� attrs_cache_ �ռ�������� |
| 106 | attrs_cache_.clear(); |
| 107 | |
| 108 | // ���ô���ӿڣ��� memcached �����ƻ������������� |
| 109 | if (!this->set_attrs(attrs_)) { |
| 110 | logger_error("set cache error, sid(%s)", sid_.c_str()); |
| 111 | attrs_clear(attrs_); // ������Լ������� |
| 112 | |
| 113 | return false; |
| 114 | } |
| 115 | |
| 116 | attrs_clear(attrs_); // ������Լ������� |
| 117 | |
| 118 | if (!sid_saved_) { |
| 119 | sid_saved_ = true; |
| 120 | } |
| 121 | return true; |
| 122 | } |
| 123 | |