public void setToCache(String key, Object value, int objectSize, 
			int expInSec) throws Exception {
		Connection con = null;
		PreparedStatement pstmt = null;
		
		java.sql.Timestamp currentTime = new java.sql.Timestamp(System.currentTimeMillis());
		java.sql.Timestamp expTime = null;

		if (expInSec != 0) {
			expTime = new java.sql.Timestamp(System.currentTimeMillis() + expInSec * 1000);
		}
		
		try {
			con = getConnection();

			pstmt = con.prepareStatement(
					"INSERT INTO DATA_CACHE (KEY, DATA, SIZE, CREATION_TIME_STAMP, EXPIRY_TIME_STAMP, LAST_ACCESS_TIME) values(?,?,?,?,?,?)");
			int k = 1;			

			pstmt.setString(k++, key);
			pstmt.setObject(k++, value);
			pstmt.setInt(k++, objectSize);

			pstmt.setTimestamp(k++, currentTime);
			pstmt.setTimestamp(k++, expTime);
			pstmt.setTimestamp(k++, currentTime);

			pstmt.executeUpdate();
		} catch (Exception e) {
			if(e.getMessage().startsWith("Unique index or primary key violation:")) {
				try {
					pstmt = con.prepareStatement(
						"UPDATE DATA_CACHE SET DATA=?, SIZE=?, CREATION_TIME_STAMP=?, EXPIRY_TIME_STAMP=?, LAST_ACCESS_TIME=? WHERE KEY=?");
					int k = 1;

					pstmt.setObject(k++, value);
					pstmt.setInt(k++, objectSize);

					pstmt.setTimestamp(k++, currentTime);
					pstmt.setTimestamp(k++, expTime);
					pstmt.setTimestamp(k++, currentTime);

					pstmt.setString(k++, key);

					pstmt.executeUpdate();
				} catch (Exception er) {
					logger.log(Level.WARNING, "Update Error: " + er, er);
					throw er;
				}
			} else {
				logger.log(Level.WARNING, "Error: " + e, e);
				throw e;
			}
		} finally {
			try {
				pstmt.close();
			} catch (SQLException e1) {
				logger.log(Level.WARNING, "Error: " + e1, e1);
			}
			try {
				con.close();
			} catch (SQLException e1) {
				logger.log(Level.WARNING, "Error: " + e1, e1);
			}
		}
	}