Giter VIP home page Giter VIP logo

codeigniter-cache's Introduction

CodeIgniter-Cache

CodeIgniter-Cache is a partial caching library for CodeIgniter. It allows you to write and get chunks of data to and from the filesystem. By storing complex or large chunks of data in serialized form on the file system you can relieve stress from the database or simply cache Twitter calls.

Requirements

  1. PHP 5.2.x
  2. CodeIgniter 2.0.x to 2.1.0

Usage

// Uncached model call
$this->blog_m->getPosts($category_id, 'live');

// cached model call
$this->cache->model('blog_m', 'getPosts', array($category_id, 'live'), 120); // keep for 2 minutes

// cached library call
$this->cache->library('some_library', 'calcualte_something', array($foo, $bar, $bla)); // keep for default time (0 = unlimited)

// cached array or object
$this->cache->write($data, 'cached-name');
$data = $this->cache->get('cached-name');

// Delete cache
$this->cache->delete('cached-name');

// Delete all cache
$this->cache->delete_all();

// Delete cache group
$this->cache->write($data, 'nav_header');
$this->cache->write($data, 'nav_footer');
$this->cache->delete_group('nav_');

// Delete cache item
// Call like a normal library or model but give a negative $expire
$this->cache->model('blog_m', 'getPosts', array($category_id, 'live'), -1); // delete this specific cache file

Installation

Permission your cache folder to be writeable by the web server.

codeigniter-cache's People

Contributors

ericlbarnes avatar jeroenvdgulik avatar philsturgeon avatar tjoosten avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

codeigniter-cache's Issues

Multiple attempts to delete the same (inexistant) file

1 errors have occured on the following session:
IP: [::1] UA: [ApacheBench/2.3] URL: [http://localhost/]
Errors:
Severity: Warning --> unlink(/www/application/cache/news_model/3e66759ca8f636b2ee7abea7f3e3e8854fd941ca.cache): Permission denied /www/application/libraries/Cache.php 372

1 errors have occured on the following session:
IP: [::1] UA: [ApacheBench/2.3] URL: [http://localhost/]
Errors:
Severity: Warning --> unlink(/www/application/cache/news_model/3e66759ca8f636b2ee7abea7f3e3e8854fd941ca.cache): Permission denied /www/application/libraries/Cache.php 372

1 errors have occured on the following session:
IP: [::1] UA: [ApacheBench/2.3] URL: [http://localhost/]
Errors:
Severity: Warning --> unlink(/www/application/cache/news_model/3e66759ca8f636b2ee7abea7f3e3e8854fd941ca.cache): Permission denied /www/application/libraries/Cache.php 372

1 errors have occured on the following session:
IP: [::1] UA: [ApacheBench/2.3] URL: [http://localhost/]
Errors:
Severity: Warning --> unlink(/www/application/cache/news_model/3e66759ca8f636b2ee7abea7f3e3e8854fd941ca.cache): No such file or directory /www/application/libraries/Cache.php 372

1 errors have occured on the following session:
IP: [::1] UA: [ApacheBench/2.3] URL: [http://localhost/]
Errors:
Severity: Warning --> unlink(/www/application/cache/news_model/3e66759ca8f636b2ee7abea7f3e3e8854fd941ca.cache): No such file or directory /www/application/libraries/Cache.php 372

This occurred while ApacheBench was running a benchmark (100 cycles). I think it detected the cache was old and attempted to delete it multiple times (race condition?). Possibly fixable with flock?

Query results not being stored in cache file.

I think I'm possibly just being a bit dim here, but I can't seem to get query results to store in cache files.
Here's the exact problem I'm having:

Upon running the database query, a cache file is created but the results from the database are not stored in it.
To add to my confusion, the results appear on the page upon first load, but then after a refresh, the cached file is then loaded instead, so no data is retrieved.

Here’s my controller - users.php

class Users extends CI_Controller {

 public function test()
 {
  $this->output->enable_profiler(TRUE);
  $this->load->model('mdl_users');

  $id = 2;
  $data['query'] = $this->cache->model('mdl_users', 'get_user', array($id), 120);
  
  $this->load->view('users', $data);
 }

} 

My model - mdl_users.php

class Mdl_users extends CI_Model {

 function get_user($id)
 {
  $this->db->where('id', $id);
  $this->db->limit(1);
  $query=$this->db->get('users');
  return $query;
 }
 
}

and my view - users.php

 foreach($query->result() as $row)
 {
  echo $row->name;
 }

And this is what is stored in the cache file

a:4:{s:16:"__cache_contents";O:19:"CI_DB_mysqli_result":8:{s:7:"conn_id";O:6:"mysqli":19:{s:13:"affected_rows";N;s:11:"client_info";N;s:14:"client_version";N;s:13:"connect_errno";N;s:13:"connect_error";N;s:5:"errno";N;s:5:"error";N;s:10:"error_list";N;s:11:"field_count";N;s:9:"host_info";N;s:4:"info";N;s:9:"insert_id";N;s:11:"server_info";N;s:14:"server_version";N;s:4:"stat";N;s:8:"sqlstate";N;s:16:"protocol_version";N;s:9:"thread_id";N;s:13:"warning_count";N;}s:9:"result_id";O:13:"mysqli_result":5:{s:13:"current_field";N;s:11:"field_count";N;s:7:"lengths";N;s:8:"num_rows";N;s:4:"type";N;}s:12:"result_array";a:0:{}s:13:"result_object";a:0:{}s:20:"custom_result_object";a:0:{}s:11:"current_row";i:0;s:8:"num_rows";i:1;s:8:"row_data";N;}s:15:"__cache_created";i:1401965162;s:20:"__cache_dependencies";a:0:{}s:15:"__cache_expires";i:1401965182;} 

I'm testing this on a vanilla install for now, but the site I'm intending to use this on could potentially be running hundreds of queries per second, so this would be brilliant if I can get it working!

Thanks for any help!

Composer?

Any chance you can update this to be loaded via composer?

Thanks for all you do for PHP.

permission

Hello mate,

I'm using your lib widely - it's nice.
But files created with library, can't be somehow deleted, their chmod shows 777, but still no luck...
don't you know what can be an issue?

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.