Skip to content

Commit

Permalink
fixed cookie bug in page cache
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.yandex.ru/xscript-core/trunk@1300 b01ef89b-65f2-463d-9415-e8412542ae63
  • Loading branch information
golubtsov authored and bacek committed Oct 10, 2014
1 parent 62de617 commit bc267aa
Show file tree
Hide file tree
Showing 33 changed files with 223 additions and 358 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
@@ -1,3 +1,9 @@
xscript (5.70.71-1) unstable; urgency=low

* fixed cookie bug in page cache

-- Ilya Golubtsov (Ilya) <golubtsov@yandex-team.ru> Tue, 11 May 2010 20:16:37 +0400

xscript (5.70.70-1) unstable; urgency=low

* deny removed in xml cache
Expand Down
3 changes: 2 additions & 1 deletion file-block/file_block.cpp
Expand Up @@ -45,7 +45,8 @@ class FStreamBinaryWriter : public BinaryWriter {
is_(is), size_(size)
{}

void write(std::ostream *os) const {
void write(std::ostream *os, const Response *response) const {
(void)response;
*os << is_->rdbuf();
}

Expand Down
3 changes: 2 additions & 1 deletion http-block/http_block.cpp
Expand Up @@ -47,7 +47,8 @@ class StringBinaryWriter : public BinaryWriter {
public:
StringBinaryWriter(boost::shared_ptr<std::string> data) : data_(data) {}

void write(std::ostream *os) const {
void write(std::ostream *os, const Response *response) const {
(void)response;
os->write(data_->data(), data_->size());
}

Expand Down
33 changes: 0 additions & 33 deletions include/internal/lrucache.h
Expand Up @@ -62,18 +62,13 @@ class LRUCache {
CacheCounter& counter_;

public:

typedef boost::function<void (const Data &data)> CleanupFunc;

explicit LRUCache(unsigned int size, bool check_expire, CacheCounter &counter);
~LRUCache();

void clear();

bool load(const Key &key, Data &data, Tag &tag);
bool load(const Key &key, Data &data, Tag &tag, const CleanupFunc &cleanFunc);
void save(const Key &key, const Data &data, const Tag &tag);
void save(const Key &key, const Data &data, const Tag &tag, const CleanupFunc &cleanFunc);

private:
void push_front(const Key &key, const Data &data, const Tag &tag);
Expand All @@ -93,15 +88,6 @@ LRUCache<Key, Data, ExpireFunc>::~LRUCache() {
template<typename Key, typename Data, typename ExpireFunc>
void
LRUCache<Key, Data, ExpireFunc>::save(const Key &key, const Data &data, const Tag &tag) {
CleanupFunc cleanFunc;
save(key, data, tag, cleanFunc);
}

template<typename Key, typename Data, typename ExpireFunc>
void
LRUCache<Key, Data, ExpireFunc>::save(
const Key &key, const Data &data, const Tag &tag, const CleanupFunc &cleanFunc) {

boost::mutex::scoped_lock lock(mutex_);

if (key2data_.empty()) {
Expand All @@ -119,9 +105,6 @@ LRUCache<Key, Data, ExpireFunc>::save(
it->second = data_.begin();
lock.unlock();
counter_.incUpdated();
if (!cleanFunc.empty()) {
cleanFunc(data_tmp);
}
return;
}

Expand All @@ -140,10 +123,6 @@ LRUCache<Key, Data, ExpireFunc>::save(

lock.unlock();
counter_.incInserted();

if (!cleanFunc.empty()) {
cleanFunc(data_tmp);
}
}

template<typename Key, typename Data, typename ExpireFunc>
Expand Down Expand Up @@ -184,15 +163,6 @@ LRUCache<Key, Data, ExpireFunc>::push_front(const Key &key, const Data &data, co
template<typename Key, typename Data, typename ExpireFunc>
bool
LRUCache<Key, Data, ExpireFunc>::load(const Key &key, Data &data, Tag &tag) {
CleanupFunc cleanFunc;
return load(key, data, tag, cleanFunc);
}

template<typename Key, typename Data, typename ExpireFunc>
bool
LRUCache<Key, Data, ExpireFunc>::load(
const Key &key, Data &data, Tag &tag, const CleanupFunc &cleanFunc) {

boost::mutex::scoped_lock lock(mutex_);

iterator it = key2data_.find(key);
Expand All @@ -208,9 +178,6 @@ LRUCache<Key, Data, ExpireFunc>::load(
key2data_.erase(it);
lock.unlock();
counter_.incExpired();
if (!cleanFunc.empty()) {
cleanFunc(data_tmp);
}
return false;
}

Expand Down
2 changes: 0 additions & 2 deletions include/xscript/context.h
Expand Up @@ -57,7 +57,6 @@ class Context : private boost::noncopyable {
void result(unsigned int n, boost::shared_ptr<InvokeContext> result);
void addNode(xmlNodePtr node);
void addDoc(XmlDocSharedHelper doc);
void addDoc(XmlDocHelper doc);

bool resultsReady() const;
boost::xtime delay(int millis) const;
Expand All @@ -75,7 +74,6 @@ class Context : private boost::noncopyable {
bool isRoot() const;
bool isProxy() const;

bool hasXslt() const;
std::string xsltName() const;
void xsltName(const std::string &value);

Expand Down
35 changes: 15 additions & 20 deletions include/xscript/doc_cache.h
Expand Up @@ -26,17 +26,15 @@ class Tag;

class CacheContext {
public:
CacheContext(CachedObject *obj, Context *ctx);
CacheContext(CachedObject *obj, Context *ctx, bool allow_distributed);
CacheContext(const CachedObject *obj);
CacheContext(const CachedObject *obj, bool allow_distributed);

CachedObject* object() const;
Context* context() const;
const CachedObject* object() const;
bool allowDistributed() const;
void allowDistributed(bool flag);

private:
CachedObject* obj_;
Context* ctx_;
const CachedObject* obj_;
bool allow_distributed_;
};

Expand All @@ -47,7 +45,6 @@ class CacheData {

virtual bool parse(const char *buf, boost::uint32_t size) = 0;
virtual void serialize(std::string &buf) = 0;
virtual void cleanup(Context *ctx) = 0;
};

class BlockCacheData : public CacheData {
Expand All @@ -58,7 +55,6 @@ class BlockCacheData : public CacheData {

virtual bool parse(const char *buf, boost::uint32_t size);
virtual void serialize(std::string &buf);
virtual void cleanup(Context *ctx);

const XmlDocSharedHelper& doc() const;
private:
Expand All @@ -74,13 +70,12 @@ class PageCacheData : public CacheData, public BinaryWriter {

virtual bool parse(const char *buf, boost::uint32_t size);
virtual void serialize(std::string &buf);
virtual void cleanup(Context *ctx);

void append(const char *buf, std::streamsize size);
void addHeader(const std::string &name, const std::string &value);
void expireTimeDelta(boost::uint32_t delta);

virtual void write(std::ostream *os) const;
virtual void write(std::ostream *os, const Response *response) const;
virtual std::streamsize size() const;

private:
Expand All @@ -103,10 +98,10 @@ class DocCacheBase {
static bool checkTag(const Context *ctx, const Tag &tag, const char *operation);

protected:
bool loadDocImpl(InvokeContext *invoke_ctx, CacheContext *cache_ctx,
Tag &tag, boost::shared_ptr<CacheData> &cache_data);
bool saveDocImpl(const InvokeContext *invoke_ctx, CacheContext *cache_ctx,
const Tag &tag, const boost::shared_ptr<CacheData> &cache_data);
bool loadDocImpl(const Context *ctx, InvokeContext *invoke_ctx,
const CacheContext *cache_ctx, Tag &tag, boost::shared_ptr<CacheData> &cache_data);
bool saveDocImpl(const Context *ctx, const InvokeContext *invoke_ctx,
const CacheContext *cache_ctx, const Tag &tag, const boost::shared_ptr<CacheData> &cache_data);

bool allow(const DocCacheStrategy* strategy, const CacheContext *cache_ctx) const;

Expand All @@ -126,10 +121,10 @@ class DocCache : public DocCacheBase {
virtual ~DocCache();
static DocCache* instance();

boost::shared_ptr<BlockCacheData> loadDoc(
InvokeContext *invoke_ctx, CacheContext *cache_ctx, Tag &tag);
bool saveDoc(const InvokeContext *invoke_ctx, CacheContext *cache_ctx,
const Tag &tag, const boost::shared_ptr<BlockCacheData> &cache_data);
boost::shared_ptr<BlockCacheData> loadDoc(const Context *ctx, InvokeContext *invoke_ctx,
const CacheContext *cache_ctx, Tag &tag);
bool saveDoc(const Context *ctx, const InvokeContext *invoke_ctx,
const CacheContext *cache_ctx, const Tag &tag, const boost::shared_ptr<BlockCacheData> &cache_data);

protected:
DocCache();
Expand All @@ -143,8 +138,8 @@ class PageCache : public DocCacheBase {
virtual ~PageCache();
static PageCache* instance();

boost::shared_ptr<PageCacheData> loadDoc(CacheContext *cache_ctx, Tag &tag);
virtual bool saveDoc(CacheContext *cache_ctx, const Tag &tag,
boost::shared_ptr<PageCacheData> loadDoc(const Context *ctx, const CacheContext *cache_ctx, Tag &tag);
virtual bool saveDoc(const Context *ctx, const CacheContext *cache_ctx, const Tag &tag,
const boost::shared_ptr<PageCacheData> &cache_data);

protected:
Expand Down
6 changes: 2 additions & 4 deletions include/xscript/doc_cache_strategy.h
Expand Up @@ -37,10 +37,8 @@ class DocCacheStrategy {
virtual std::string name() const = 0;
virtual std::auto_ptr<TagKey> createKey(const Context *ctx, const CachedObject *obj) const = 0;

virtual bool loadDoc(const TagKey *key, CacheContext *cache_ctx,
Tag &tag, boost::shared_ptr<CacheData> &cache_data) = 0;
virtual bool saveDoc(const TagKey *key, CacheContext *cache_ctx,
const Tag& tag, const boost::shared_ptr<CacheData> &cache_data) = 0;
virtual bool loadDoc(const TagKey *key, Tag &tag, boost::shared_ptr<CacheData> &cache_data) = 0;
virtual bool saveDoc(const TagKey *key, const Tag& tag, const boost::shared_ptr<CacheData> &cache_data) = 0;

virtual void fillStatBuilder(StatBuilder *builder);

Expand Down
2 changes: 1 addition & 1 deletion include/xscript/response.h
Expand Up @@ -49,7 +49,7 @@ class Response : private boost::noncopyable {
const CookieSet& outCookies() const;
boost::uint32_t expireDelta() const;

void detach(Context *ctx);
void detach(const Context *ctx);
void setCacheable(
boost::shared_ptr<PageCacheData> cache_data = boost::shared_ptr<PageCacheData>());

Expand Down
2 changes: 1 addition & 1 deletion include/xscript/server.h
Expand Up @@ -34,7 +34,7 @@ class Server : private boost::noncopyable {
void handleRequest(const boost::shared_ptr<Request> &request,
const boost::shared_ptr<Response> &response,
boost::shared_ptr<Context> &ctx);
bool processCachedDoc(Context *ctx, Script *script);
bool processCachedDoc(Context *ctx, const Script *script);
void sendResponse(Context *ctx, XmlDocSharedHelper doc);

virtual boost::shared_ptr<Script> getScript(Request *request);
Expand Down
2 changes: 1 addition & 1 deletion include/xscript/writer.h
Expand Up @@ -23,7 +23,7 @@ class BinaryWriter : private boost::noncopyable {
public:
virtual ~BinaryWriter();

virtual void write(std::ostream *os) const = 0;
virtual void write(std::ostream *os, const Response *response) const = 0;
virtual std::streamsize size() const = 0;
};

Expand Down
2 changes: 1 addition & 1 deletion library/block.cpp
Expand Up @@ -573,7 +573,7 @@ Block::applyStylesheet(boost::shared_ptr<Context> ctx, XmlDocSharedHelper &doc)
PROFILER(log(), std::string("per-block-xslt: '") + xsltName() +
"' block: '" + name() + "' block-id: '" + id() +
"' method: '" + method() + "' owner: '" + owner()->name() + "'");
Object::applyStylesheet(sh, ctx, doc, XmlUtils::xmlVersionNumber() < 20619);
Object::applyStylesheet(sh, ctx, doc, true);
}

XmlUtils::throwUnless(NULL != doc->get());
Expand Down

0 comments on commit bc267aa

Please sign in to comment.